Skip to content

fix: Efficient build menu for versioned and unversioned pages #7807

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
merged 12 commits into from
Feb 29, 2024

Conversation

fsbraun
Copy link
Member

@fsbraun fsbraun commented Feb 8, 2024

Description

With djangocms-versioning activated, building menus can take extremely long times for large sites (#7805). While djangocms-versioning's own menu class is not efficient, the django CMS core menu class does not utilize the admin_manager and fails when run on versioned pages.

This PR updates django CMS core's menus with three cornerstones in mind

  • Efficient database access (n=6 including permissions)
  • Adherence to the language fallback settings
  • Using admin_manager and preview endpoints allowing to be extended by packages like djangocms-versioning

To use the core's menu system with djangocms-versioning you have to include to following setting in settings.py:

DJANGOCMS_VERSIONING_ENABLE_MENU_REGISTRATION = False

In comparison, djangocms-versioning's menus are slower and do not respect the language fallbacks.

Related resources

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.

@fsbraun fsbraun requested a review from a team February 8, 2024 10:07
@marksweb marksweb self-requested a review February 11, 2024 11:34
Comment on lines -212 to -235
pages
.filter(pagecontent_set__language__in=languages)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This query gets looped through on line 275 and it's looking at the related set without a prefetch. I think we should add a one;

pages.prefetch_related(
    'pagecontent_set'
).filter(pagecontent_set__language__in=languages)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! The pages queryset gets turned into a list when get_visible_nodes is called. Let me have a look at get_visible_nodes to return a queryset instead of a list. A first glance, it gives the impression there is room for further performance improvement. Maybe we can save another query?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marksweb Now, I've looked into that. pages is pushed as an iterable into prefetch_related. So the prefetch is done manually there.

Keeping it as a queryset, is I hoped would improve the database accesses, therefore will not do so. Also, the permissions cache is filled, which - if get_visible_nodes needed to return a qs - would not be possible and might lead to performance penalties later. Finally, the permission rules are quite complicated. Turning them into queries is not immediately obvious.

I would stay with the current structure.

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.

3 participants