kopia lustrzana https://github.com/wagtail/wagtail
adjusted queries to ignore expired embeds (#7279)
rodzic
de8ee5ed99
commit
a64eb1f2f3
|
@ -22,6 +22,7 @@ Changelog
|
|||
* Fix: Prevent error when filtering page search results with a malformed content_type (Chris Pollard)
|
||||
* Fix: Prevent multiple submissions of "update" form when uploading images / documents (Mike Brown)
|
||||
* Fix: Ensure HTML title is populated on project template 404 page (Matt Westcott)
|
||||
* Fix: Respect cache_age parameters on embeds (Gordon Pendleton)
|
||||
|
||||
|
||||
2.13.2 (17.06.2021)
|
||||
|
|
|
@ -33,6 +33,7 @@ Bug fixes
|
|||
* Prevent error when filtering page search results with a malformed content_type (Chris Pollard)
|
||||
* Prevent multiple submissions of "update" form when uploading images / documents (Mike Brown)
|
||||
* Ensure HTML title is populated on project template 404 page (Matt Westcott)
|
||||
* Respect cache_age parameters on embeds (Gordon Pendleton)
|
||||
|
||||
Upgrade considerations
|
||||
======================
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
from datetime import datetime
|
||||
from hashlib import md5
|
||||
|
||||
from django.utils.timezone import now
|
||||
|
||||
from .exceptions import EmbedUnsupportedProviderException
|
||||
from .finders import get_finders
|
||||
from .models import Embed
|
||||
|
@ -11,7 +13,7 @@ def get_embed(url, max_width=None, finder=None):
|
|||
|
||||
# Check database
|
||||
try:
|
||||
return Embed.objects.get(hash=embed_hash)
|
||||
return Embed.objects.exclude(cache_until__lte=now()).get(hash=embed_hash)
|
||||
except Embed.DoesNotExist:
|
||||
pass
|
||||
|
||||
|
@ -47,12 +49,12 @@ def get_embed(url, max_width=None, finder=None):
|
|||
embed_dict['thumbnail_url'] = ''
|
||||
|
||||
# Create database record
|
||||
embed, created = Embed.objects.get_or_create(
|
||||
embed, created = Embed.objects.update_or_create(
|
||||
hash=embed_hash,
|
||||
defaults=dict(
|
||||
url=url,
|
||||
max_width=max_width,
|
||||
**embed_dict,
|
||||
**embed_dict
|
||||
)
|
||||
)
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ from django import template
|
|||
from django.core.exceptions import ValidationError
|
||||
from django.test import TestCase, override_settings
|
||||
from django.urls import reverse
|
||||
from django.utils.timezone import make_aware
|
||||
from django.utils.timezone import make_aware, now
|
||||
|
||||
from wagtail.core import blocks
|
||||
from wagtail.embeds import oembed_providers
|
||||
|
@ -192,6 +192,23 @@ class TestEmbeds(TestCase):
|
|||
def test_get_embed_cache_until(self):
|
||||
embed = get_embed('www.test.com/1234', max_width=400, finder=self.dummy_cache_until_finder)
|
||||
self.assertEqual(embed.cache_until, make_aware(datetime.datetime(2001, 2, 3)))
|
||||
self.assertEqual(self.hit_count, 1)
|
||||
|
||||
# expired cache_until should be ignored
|
||||
embed_2 = get_embed('www.test.com/1234', max_width=400, finder=self.dummy_cache_until_finder)
|
||||
self.assertEqual(self.hit_count, 2)
|
||||
|
||||
# future cache_until should not be ignored
|
||||
future_dt = now() + datetime.timedelta(minutes=1)
|
||||
embed.cache_until = future_dt
|
||||
embed.save()
|
||||
embed_3 = get_embed('www.test.com/1234', max_width=400, finder=self.dummy_cache_until_finder)
|
||||
self.assertEqual(self.hit_count, 2)
|
||||
|
||||
# ensure we've received the same embed
|
||||
self.assertEqual(embed, embed_2)
|
||||
self.assertEqual(embed, embed_3)
|
||||
self.assertEqual(embed_3.cache_until, future_dt)
|
||||
|
||||
def dummy_finder_invalid_width(self, url, max_width=None):
|
||||
# Return a record with an invalid width
|
||||
|
|
Ładowanie…
Reference in New Issue