Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
djangoldp
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
djangoldp-packages
djangoldp
Commits
fda9b049
Commit
fda9b049
authored
4 years ago
by
Jean-Baptiste
Browse files
Options
Downloads
Patches
Plain Diff
syntax: clean up
parent
110f8fcb
No related branches found
Branches containing commit
No related tags found
1 merge request
!173
Improve serializer cache
Pipeline
#8290
passed
4 years ago
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
djangoldp/permissions.py
+9
-6
9 additions, 6 deletions
djangoldp/permissions.py
djangoldp/tests/tests_perf_get.py
+1
-0
1 addition, 0 deletions
djangoldp/tests/tests_perf_get.py
with
10 additions
and
6 deletions
djangoldp/permissions.py
+
9
−
6
View file @
fda9b049
...
...
@@ -38,18 +38,15 @@ class LDPPermissions(DjangoObjectPermissions):
Filter user permissions for a model class
"""
# this may be a permission for the model class, or an instance
self
.
refresh_cache
()
# this may be a permission for the model class, or an instance
if
isinstance
(
obj_or_model
,
ModelBase
):
model
=
obj_or_model
else
:
obj
=
obj_or_model
model
=
obj_or_model
.
__class__
model_name
=
model
.
_meta
.
model_name
user_key
=
'
None
'
if
user
is
None
else
user
.
id
obj_key
=
'
None
'
if
obj
is
None
else
obj
.
id
perms_cache_key
=
'
User{}{}{}
'
.
format
(
user_key
,
model_name
,
obj_key
)
perms_cache_key
=
self
.
cache_key
(
model
,
obj
,
user
)
if
self
.
with_cache
and
perms_cache_key
in
self
.
perms_cache
:
return
self
.
perms_cache
[
perms_cache_key
]
...
...
@@ -95,7 +92,13 @@ class LDPPermissions(DjangoObjectPermissions):
self
.
perms_cache
[
perms_cache_key
]
=
list
(
perms
)
return
self
.
perms_cache
[
perms_cache_key
]
# return list(perms)
def
cache_key
(
self
,
model
,
obj
,
user
):
model_name
=
model
.
_meta
.
model_name
user_key
=
'
None
'
if
user
is
None
else
user
.
id
obj_key
=
'
None
'
if
obj
is
None
else
obj
.
id
perms_cache_key
=
'
User{}{}{}
'
.
format
(
user_key
,
model_name
,
obj_key
)
return
perms_cache_key
def
filter_user_perms
(
self
,
context
,
obj_or_model
,
permissions
):
# Only used on Model.get_permissions to translate permissions to LDP
...
...
This diff is collapsed.
Click to expand it.
djangoldp/tests/tests_perf_get.py
+
1
−
0
View file @
fda9b049
...
...
@@ -18,6 +18,7 @@ class TestPerformanceGET(APITestCase):
result_line
=
[]
withAuth
=
True
withPermsCache
=
True
# fixtures = ['test_ten_1000.json',]
@classmethod
def
setUpClass
(
cls
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment