Modify image.get_rendition() to take advantage of prefetch_related
See original GitHub issueThe 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:
- Created 9 years ago
- Comments:11 (8 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Will mark this as closed as #8069 has been merged and is available since Wagtail 3 And Wagtail 4 also has #8584
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