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

perf: small reduction of DB queries #7887

Open
wants to merge 4 commits into
base: develop-4
Choose a base branch
from

Conversation

jrief
Copy link
Contributor

@jrief jrief commented Apr 23, 2024

Description

This PR reduces the number of DB queries by a few.

Related resources

  1. chunk: fallback languages can be cached inside the Page object.
  2. chunk: Replacing the .filter(…) on the queryset against .all() actually reduces the number of queries. This is because that queryset in most cases is already consumed. Calling it with .filter(…) actually fetches the data a second time. Therefore filtering in Python is cheaper, especially if the number of languages never exceeds a significant number.

Also read https://docs.djangoproject.com/en/5.0/ref/models/querysets/#values

Checklist

  • I have opened this pull request against develop-4
  • I have added or modified the tests when changing logic
  • I have followed the conventional commits guidelines to add meaningful information into the changelog
  • I have read the contribution guidelines and I have joined #workgroup-pr-review on Slack to find a “pr review buddy” who is going to review my pull request.

@jrief jrief changed the title small reduction of DB queries [perf] small reduction of DB queries Apr 23, 2024
@marksweb marksweb changed the title [perf] small reduction of DB queries perf: small reduction of DB queries Apr 23, 2024
@fsbraun
Copy link
Sponsor Member

fsbraun commented Apr 24, 2024

I like the all() optimisation.

How does caching the fallback languages help performance. The fallback languages only depend on the settings, or am I missing something?

@vinitkumar
Copy link
Member

@jrief Are there any updates on this? Also, would be great to see the number of queries reduction shown by Django Debug Tool or something? In my opinion, it would be help remember the rationale behind the change in future.

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

Successfully merging this pull request may close these issues.

None yet

3 participants