-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
fix: Refactor menus app: significant time saving (queries and cpu) #7956
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
… one big query) by building the nodes based on page content objects instead of page objects
marksweb
reviewed
Jul 22, 2024
4 tasks
marksweb
approved these changes
Jul 22, 2024
I added benchmarks from https://github.com/fsbraun/django-cms-benchmark:
Before
After
|
4 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Menu creation takes significant time for installations with a large number of pages. This PR reduces time needed for creating the menu and rendering the menu. Measurements were done on a test installation with ~55,000 pages (SQLite db).
Improvement 1: Generating the navigation node list
Creation of menu nodes is cached. So, this is a one-time gain after, say, adding a page.
The efficiency gain comes from identifying the relevant page content object only once per page object when translating the page list into a menu node list.
Improvement 2: Rendering the menu
The second angle of attack are the menu template tags: They depend on the
cut_levels
implementation, which was very inefficient. Especially, theextra_inactive
parameter indicating how many inactive children should be present in the navigation had a computational time of O(n) with n being the number of pages/menu entries. The PR makes reduces this O(1).Improvement 3: Versioning-induced db hits
An N+1 issue is introduced when generating the menu nodes through djangocms-versioning. Each menu node is checked against the home page to check if it needs to be cut. For this, the home page needs to be not in the navigation. Since, "not in navigation" is a page content property, this check triggers a database hit to find the relevant page content version. This PR only checks once if the home page is in the menu.
Additional improvement potential
@jrief Can you help to test this in a realistic environment?
Related resources
Checklist
develop-4