Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
6e2d9883
Commit
6e2d9883
authored
Jan 19, 2016
by
David Ormsbee
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make role lookup faster.
parent
403f03e7
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
8 deletions
+10
-8
common/djangoapps/student/roles.py
+10
-8
No files found.
common/djangoapps/student/roles.py
View file @
6e2d9883
...
...
@@ -36,23 +36,25 @@ def register_access_role(cls):
class
RoleCache
(
object
):
"""
A cache of the CourseAccessRoles held by a particular user
A cache of the CourseAccessRoles held by a particular user.
We do everything we can to avoid de-serialization overhead with CourseKeys,
since this is so frequently used.
"""
def
__init__
(
self
,
user
):
self
.
_roles
=
set
(
CourseAccessRole
.
objects
.
filter
(
user
=
user
)
.
all
(
)
CourseAccessRole
.
objects
.
filter
(
user
=
user
)
.
values_list
(
'role'
,
'course_id'
,
'org'
)
)
def
has_role
(
self
,
role
,
course_id
,
org
):
"""
Return whether this RoleCache contains a role with the specified role, course_id, and org
"""
return
any
(
access_role
.
role
==
role
and
access_role
.
course_id
==
course_id
and
access_role
.
org
==
org
for
access_role
in
self
.
_roles
)
# OpaqueKeyField serialization is such that a blank in the DB gets
# translated to a None.
if
course_id
is
None
:
course_id
=
''
return
(
role
,
unicode
(
course_id
),
org
)
in
self
.
_roles
class
AccessRole
(
object
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment