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
4b2c4e71
Commit
4b2c4e71
authored
Aug 15, 2012
by
Calen Pennington
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #414 from MITx/kimth/xqueue_callback_blocking
Rename acquire_lock to select_for_update, add docstring
parents
b2df6d94
42ea4f32
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
5 deletions
+7
-5
lms/djangoapps/courseware/models.py
+6
-4
lms/djangoapps/courseware/module_render.py
+1
-1
No files found.
lms/djangoapps/courseware/models.py
View file @
4b2c4e71
...
...
@@ -67,7 +67,7 @@ class StudentModuleCache(object):
"""
A cache of StudentModules for a specific student
"""
def
__init__
(
self
,
user
,
descriptors
,
acquire_lock
=
False
):
def
__init__
(
self
,
user
,
descriptors
,
select_for_update
=
False
):
'''
Find any StudentModule objects that are needed by any descriptor
in descriptors. Avoids making multiple queries to the database.
...
...
@@ -77,6 +77,7 @@ class StudentModuleCache(object):
Arguments
user: The user for which to fetch maching StudentModules
descriptors: An array of XModuleDescriptors.
select_for_update: Flag indicating whether the row should be locked until end of transaction
'''
if
user
.
is_authenticated
():
module_ids
=
self
.
_get_module_state_keys
(
descriptors
)
...
...
@@ -86,7 +87,7 @@ class StudentModuleCache(object):
self
.
cache
=
[]
chunk_size
=
500
for
id_chunk
in
[
module_ids
[
i
:
i
+
chunk_size
]
for
i
in
xrange
(
0
,
len
(
module_ids
),
chunk_size
)]:
if
acquire_lock
:
if
select_for_update
:
self
.
cache
.
extend
(
StudentModule
.
objects
.
select_for_update
()
.
filter
(
student
=
user
,
module_state_key__in
=
id_chunk
)
...
...
@@ -102,13 +103,14 @@ class StudentModuleCache(object):
@classmethod
def
cache_for_descriptor_descendents
(
cls
,
user
,
descriptor
,
depth
=
None
,
descriptor_filter
=
lambda
descriptor
:
True
,
acquire_lock
=
False
):
def
cache_for_descriptor_descendents
(
cls
,
user
,
descriptor
,
depth
=
None
,
descriptor_filter
=
lambda
descriptor
:
True
,
select_for_update
=
False
):
"""
descriptor: An XModuleDescriptor
depth is the number of levels of descendent modules to load StudentModules for, in addition to
the supplied descriptor. If depth is None, load all descendent StudentModules
descriptor_filter is a function that accepts a descriptor and return wether the StudentModule
should be cached
select_for_update: Flag indicating whether the row should be locked until end of transaction
"""
def
get_child_descriptors
(
descriptor
,
depth
,
descriptor_filter
):
...
...
@@ -128,7 +130,7 @@ class StudentModuleCache(object):
descriptors
=
get_child_descriptors
(
descriptor
,
depth
,
descriptor_filter
)
return
StudentModuleCache
(
user
,
descriptors
,
acquire_lock
)
return
StudentModuleCache
(
user
,
descriptors
,
select_for_update
)
def
_get_module_state_keys
(
self
,
descriptors
):
'''
...
...
lms/djangoapps/courseware/module_render.py
View file @
4b2c4e71
...
...
@@ -308,7 +308,7 @@ def xqueue_callback(request, course_id, userid, id, dispatch):
user
=
User
.
objects
.
get
(
id
=
userid
)
student_module_cache
=
StudentModuleCache
.
cache_for_descriptor_descendents
(
user
,
modulestore
()
.
get_item
(
id
),
depth
=
0
,
acquire_lock
=
True
)
user
,
modulestore
()
.
get_item
(
id
),
depth
=
0
,
select_for_update
=
True
)
instance
=
get_module
(
user
,
request
,
id
,
student_module_cache
)
if
instance
is
None
:
log
.
debug
(
"No module {} for user {}--access denied?"
.
format
(
id
,
user
))
...
...
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