Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lots of duplicated queries #617

Open
bixbyr opened this issue May 30, 2023 · 1 comment
Open

Lots of duplicated queries #617

bixbyr opened this issue May 30, 2023 · 1 comment

Comments

@bixbyr
Copy link

bixbyr commented May 30, 2023

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
Copy link
Contributor

benzkji commented Nov 4, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants