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
42ea4f32
Commit
42ea4f32
authored
Aug 15, 2012
by
kimth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename acquire_lock to select_for_update, add docstring
parent
75eee443
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 @
42ea4f32
...
@@ -67,7 +67,7 @@ class StudentModuleCache(object):
...
@@ -67,7 +67,7 @@ class StudentModuleCache(object):
"""
"""
A cache of StudentModules for a specific student
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
Find any StudentModule objects that are needed by any descriptor
in descriptors. Avoids making multiple queries to the database.
in descriptors. Avoids making multiple queries to the database.
...
@@ -77,6 +77,7 @@ class StudentModuleCache(object):
...
@@ -77,6 +77,7 @@ class StudentModuleCache(object):
Arguments
Arguments
user: The user for which to fetch maching StudentModules
user: The user for which to fetch maching StudentModules
descriptors: An array of XModuleDescriptors.
descriptors: An array of XModuleDescriptors.
select_for_update: Flag indicating whether the row should be locked until end of transaction
'''
'''
if
user
.
is_authenticated
():
if
user
.
is_authenticated
():
module_ids
=
self
.
_get_module_state_keys
(
descriptors
)
module_ids
=
self
.
_get_module_state_keys
(
descriptors
)
...
@@ -86,7 +87,7 @@ class StudentModuleCache(object):
...
@@ -86,7 +87,7 @@ class StudentModuleCache(object):
self
.
cache
=
[]
self
.
cache
=
[]
chunk_size
=
500
chunk_size
=
500
for
id_chunk
in
[
module_ids
[
i
:
i
+
chunk_size
]
for
i
in
xrange
(
0
,
len
(
module_ids
),
chunk_size
)]:
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
(
self
.
cache
.
extend
(
StudentModule
.
objects
.
select_for_update
()
.
filter
(
student
=
user
,
student
=
user
,
module_state_key__in
=
id_chunk
)
module_state_key__in
=
id_chunk
)
...
@@ -102,13 +103,14 @@ class StudentModuleCache(object):
...
@@ -102,13 +103,14 @@ class StudentModuleCache(object):
@classmethod
@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
descriptor: An XModuleDescriptor
depth is the number of levels of descendent modules to load StudentModules for, in addition to
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
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
descriptor_filter is a function that accepts a descriptor and return wether the StudentModule
should be cached
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
):
def
get_child_descriptors
(
descriptor
,
depth
,
descriptor_filter
):
...
@@ -128,7 +130,7 @@ class StudentModuleCache(object):
...
@@ -128,7 +130,7 @@ class StudentModuleCache(object):
descriptors
=
get_child_descriptors
(
descriptor
,
depth
,
descriptor_filter
)
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
):
def
_get_module_state_keys
(
self
,
descriptors
):
'''
'''
...
...
lms/djangoapps/courseware/module_render.py
View file @
42ea4f32
...
@@ -302,7 +302,7 @@ def xqueue_callback(request, course_id, userid, id, dispatch):
...
@@ -302,7 +302,7 @@ def xqueue_callback(request, course_id, userid, id, dispatch):
user
=
User
.
objects
.
get
(
id
=
userid
)
user
=
User
.
objects
.
get
(
id
=
userid
)
student_module_cache
=
StudentModuleCache
.
cache_for_descriptor_descendents
(
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
)
instance
=
get_module
(
user
,
request
,
id
,
student_module_cache
)
instance_module
=
get_instance_module
(
user
,
instance
,
student_module_cache
)
instance_module
=
get_instance_module
(
user
,
instance
,
student_module_cache
)
...
...
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