-
-
Notifications
You must be signed in to change notification settings - Fork 128
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
Fix _perm_cache
processing
#498
Changes from all commits
5feaf80
19138d5
1bb8881
4b72da2
6e5d160
cc8f331
eeb03c8
6701d15
735f138
e4b067d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -125,11 +125,10 @@ def filter_for_user_q( | |||||
raise ValueError(f"Cannot mix app_labels ({app_labels!r})") | ||||||
|
||||||
# Small optimization if the user's permissions are cached | ||||||
perm_cache = getattr(user, "_perm_cache", None) | ||||||
if perm_cache is not None: # pragma:nocover | ||||||
perm_cache: Optional[Set[str]] = getattr(user, "_perm_cache", None) | ||||||
if perm_cache is not None: | ||||||
f = any if any_perm else all | ||||||
user_perms: Set[str] = {p.codename for p in perm_cache} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (bug_risk): This change assumes that
Suggested change
|
||||||
if f(p in user_perms for p in perms_list): | ||||||
if f(p in perm_cache for p in perms_list): | ||||||
return qs | ||||||
|
||||||
q = Q() | ||||||
|
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.
issue (performance): The removal of the explicit set creation and type hint for
user_perms
simplifies the code. However, ensure thatperm_cache
directly supports efficient membership testing as a set does. Ifperm_cache
is a list or another data structure with O(n) lookup time, this change could negatively impact performance, especially with a large number of permissions.