Skip to content

Commit

Permalink
Query registry once
Browse files Browse the repository at this point in the history
instead of querying it for each img tag.
  • Loading branch information
gotcha committed Jun 26, 2023
1 parent e63ba77 commit b619daf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions news/less_call_to_registry.internal
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Call registry once per filter rather than for each img tag.
[gotcha]
5 changes: 4 additions & 1 deletion plone/outputfilters/filters/picture_variants.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def __init__(self, context=None, request=None):
self.context = context
self.request = request
self.img2picturetag = Img2PictureTag()
self.all_picture_variants = get_picture_variants()

def __call__(self, data):
soup = BeautifulSoup(safe_text(data), "html.parser")
Expand All @@ -33,7 +34,9 @@ def __call__(self, data):
picture_variant_name = elem.attrs.get("data-picturevariant", "")
if not picture_variant_name:
continue
picture_variants_config = get_picture_variants().get(picture_variant_name)
picture_variants_config = self.all_picture_variants.get(
picture_variant_name
)
if not picture_variants_config:
logger.warning(
"Could not find the given picture_variant_name {}, leave tag untouched!".format(
Expand Down

0 comments on commit b619daf

Please sign in to comment.