SmileyChris / easy-thumbnails

Easy thumbnails for Django
http://easy-thumbnails.readthedocs.org/
BSD 3-Clause "New" or "Revised" License
1.38k stars 318 forks source link

Lots of duplicated queries #617

Open bixbyr opened 1 year ago

bixbyr commented 1 year ago

I am generating a crazy huge number of queries on pages where I have a lot of thumbnails. The django-debug-toolbar is showing me this comes from some places where I am iterating through a query set and getting a thumbnail for each item. Is there a way to select_related or otherwise solve the N+1 problem here? I don't see anything in the documentation which seems like it would answer this.

benzkji commented 11 months ago

It will probably be hard with a select related, just because it's a template tag. I noticed the same as you, when rendering many thumbnails. It gets slow. I wonder if adding another cache layer could help - redis/memcached and the like would sure be much faster, than the Django ORM.

Adds more complexity, though. You could cache your template fragement, but that depends on your use case: https://docs.djangoproject.com/en/4.2/topics/cache/#template-fragment-caching