diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 1ecefe9d31..cc4661370c 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -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) diff --git a/CONTRIBUTORS.rst b/CONTRIBUTORS.rst index baeb965567..71bdf6e9a2 100644 --- a/CONTRIBUTORS.rst +++ b/CONTRIBUTORS.rst @@ -438,6 +438,7 @@ Contributors * dtwm * Steve Lyall * Lars van de Kerkhof +* pimarc Translators =========== diff --git a/docs/releases/2.9.rst b/docs/releases/2.9.rst index 43bd61518c..7497743176 100644 --- a/docs/releases/2.9.rst +++ b/docs/releases/2.9.rst @@ -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 diff --git a/wagtail/core/blocks/base.py b/wagtail/core/blocks/base.py index 0a532c5af9..202039d8d8 100644 --- a/wagtail/core/blocks/base.py +++ b/wagtail/core/blocks/base.py @@ -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):