-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
feat: Performant permission calculation for pages #7943
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
fsbraun
merged 12 commits into
django-cms:develop-4
from
fsbraun:feat/permission_performance
Jul 10, 2024
Merged
feat: Performant permission calculation for pages #7943
fsbraun
merged 12 commits into
django-cms:develop-4
from
fsbraun:feat/permission_performance
Jul 10, 2024
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
…s.utils.page_permissions.has_generic_permission`
jrief
approved these changes
Jul 2, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our team experienced a notifiable performance gain after applying this patch.
There haven't been any unexpected side effects.
fsbraun
added a commit
that referenced
this pull request
Jul 10, 2024
* Feat: Calculating page permissions does not require evaluating the full page tree * Fix N+1 issue, cache all calculated permissions * Deprecate `cms.utils.permissions.has_page_permission` in favor of `cms.utils.page_permissions.has_generic_permission` * Deprecate `.get_page_ids` since it is less efficient * Fix: get_draft_placholders * Fix: Delete permissions * Add compatibility shims with deprecation warning * Fix ruff issue
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
With permissions by page activated, the CMS needs to traverse the page tree to find permissions which apply to a specific page. For each permission, django CMS calculates the list of page IDs it applies to. This calculation is cached.
For projects with large numbers of pages (>> 1,000) these calculations generate long lists of IDs and even using the cached calculations impacts responsiveness.
This PR noticeably improves the responsiveness when working with large page trees.
This PR optimizes the calculation of permission based on a page's
path
(actually a tuplegrant_on
andpath
, where thegrant_on
code defines if the permission applies to the page itself, its direct children, and/or all of its descendants). This makes both calculating the permissions and evaluating the cached permissions from O(n) to O(1) (n being the number of pages) (but stays O(m) for m being the number of permissions granted).Thanks to @jrief for testing.
@Aiden-RC Please be invited to test and comment!
Thanks to @vinitkumar for testing a backport to django CMS 3.11.
Deprecations
This PR deprecates some (not officially documented) utility functions in
cms.utils.page.permissions
which are replaced by their counterparts getting the permission tuples, e.g.,get_add_perm_tuples
:It also deprecates the
get_page_ids
method of thecms.models.PagePermissions
model.Their database access is not efficient and redundant.
Related resources
Checklist
develop-4