question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Modify image.get_rendition() to take advantage of prefetch_related

See original GitHub issue

The Picturefill polyfill makes it possible to output responsive img tags using srcset with cross browser support.

image.get_rendition() does not take advantage of prefetch_related because of the way the rendition lookup is written. (ref: models.py#L172)

Since a responsive img tag links to many renditions, rendering a lot of images greatly increases the number of database queries. I.e. to output an image gallery with 30 images using 10 possible renditions per srcset suddenly takes 300 roundtrips to the database for renditions.

It would be beneficial to use

            renditions = self.renditions.all()
            rendition = python_selection_func(renditions, filter, vary_key)

instead of

            rendition = self.renditions.get(
                filter=filter,
                focal_point_key=vary_key,
            )

so that prefetch_related could be utilized.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:11 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
zerolabcommented, Sep 17, 2022

Will mark this as closed as #8069 has been merged and is available since Wagtail 3 And Wagtail 4 also has #8584

2reactions
zerolabcommented, May 28, 2019

There was some work in this area - #2461 / #4856 introduce an image_url template tag (usage docs) that should help for this type of scenarios

Read more comments on GitHub >

github_iconTop Results From Across the Web

Wagtail "prefetch" image urls for multiple pages - Stack Overflow
So get_image_model_string() returns a model to import as "image model", that model has an image field and probably a str() method that ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found