Add cache to speed up compiling media declarations for stream blocks

As proposed by @pimarc in https://github.com/wagtail/wagtail/issues/3062#issuecomment-586331423
pull/5896/head
Matt Westcott 2020-02-25 23:00:33 +00:00
rodzic a34d509f7e
commit f83977c291
4 zmienionych plików z 16 dodań i 1 usunięć

Wyświetl plik

@ -18,6 +18,7 @@ Changelog
* Allow free tagging to be disabled on custom tag models (Matt Westcott)
* Allow disabling page preview by setting `preview_modes` to an empty list (Casper Timmers)
* Add Vidyard to oEmbed provider list (Steve Lyall)
* Optimise compiling media definitions for complex StreamBlocks (pimarc)
* Fix: Added ARIA alert role to live search forms in the admin (Casper Timmers)
* Fix: Reorder login form elements to match expected tab order (Kjartan Sverrisson)
* Fix: Re-add 'Close Explorer' button on mobile viewports (Sævar Öfjörð Magnússon)

Wyświetl plik

@ -438,6 +438,7 @@ Contributors
* dtwm
* Steve Lyall
* Lars van de Kerkhof
* pimarc
Translators
===========

Wyświetl plik

@ -31,6 +31,7 @@ Other features
* Allow free tagging to be disabled on custom tag models (Matt Westcott)
* Allow disabling page preview by setting ``preview_modes`` to an empty list (Casper Timmers)
* Add Vidyard to oEmbed provider list (Steve Lyall)
* Optimise compiling media definitions for complex StreamBlocks (pimarc)
Bug fixes

Wyświetl plik

@ -73,8 +73,20 @@ class Block(metaclass=BaseBlock):
def all_media(self):
media = forms.Media()
# In cases where the same block definition appears multiple times within different
# container blocks (e.g. a RichTextBlock appearing at the top level of a StreamField as
# well as both sides of a StructBlock for producing two-column layouts), we will encounter
# identical media declarations. Adding these to the final combined media declaration would
# be redundant and add processing time when determining the final media ordering. To avoid
# this, we keep a cache of previously-seen declarations and only add unique ones.
media_cache = set()
for block in self.all_blocks():
media += block.media
key = block.media.__repr__()
if key not in media_cache:
media += block.media
media_cache.add(key)
return media
def all_html_declarations(self):