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
90597276
Commit
90597276
authored
Mar 09, 2015
by
Calen Pennington
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract cache instantiation into classes per-scope
parent
fd0c47bc
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
75 additions
and
21 deletions
+75
-21
lms/djangoapps/courseware/model_data.py
+75
-21
No files found.
lms/djangoapps/courseware/model_data.py
View file @
90597276
...
...
@@ -68,6 +68,63 @@ def _chunked_query(model_class, select_for_update, chunk_field, items, chunk_siz
return
res
class
UserStateCache
(
object
):
"""
Cache for Scope.user_state xblock field data.
"""
def
__init__
(
self
,
user
,
course_id
,
usage_keys
,
select_for_update
=
False
):
self
.
_data
=
_chunked_query
(
StudentModule
,
select_for_update
,
'module_state_key__in'
,
usage_keys
,
course_id
=
course_id
,
student
=
user
.
pk
,
)
class
UserStateSummaryCache
(
object
):
"""
Cache for Scope.user_state_summary xblock field data.
"""
def
__init__
(
self
,
usage_keys
,
fields
,
select_for_update
=
False
):
self
.
_data
=
_chunked_query
(
XModuleUserStateSummaryField
,
select_for_update
,
'usage_id__in'
,
usage_keys
,
field_name__in
=
set
(
field
.
name
for
field
in
fields
),
)
class
PreferencesCache
(
object
):
"""
Cache for Scope.preferences xblock field data.
"""
def
__init__
(
self
,
user
,
block_types
,
fields
,
select_for_update
=
False
):
self
.
_data
=
_chunked_query
(
XModuleStudentPrefsField
,
select_for_update
,
'module_type__in'
,
block_types
,
student
=
user
.
pk
,
field_name__in
=
set
(
field
.
name
for
field
in
fields
),
)
class
UserInfoCache
(
object
):
"""
Cache for Scope.user_info xblock field data
"""
def
__init__
(
self
,
user
,
fields
,
select_for_update
=
False
):
self
.
_data
=
_query
(
XModuleStudentInfoField
,
select_for_update
,
student
=
user
.
pk
,
field_name__in
=
set
(
field
.
name
for
field
in
fields
),
)
class
FieldDataCache
(
object
):
"""
A cache of django model objects needed to supply the data
...
...
@@ -201,38 +258,35 @@ class FieldDataCache(object):
Queries the database for all of the fields in the specified scope
"""
if
scope
==
Scope
.
user_state
:
return
_chunked_query
(
StudentModule
,
self
.
select_for_update
,
'module_state_key__in'
,
self
.
user_state_cache
=
UserStateCache
(
self
.
user
,
self
.
course_id
,
self
.
_all_usage_ids
(
descriptors
),
course_id
=
self
.
course_id
,
student
=
self
.
user
.
pk
,
self
.
select_for_update
,
)
return
self
.
user_state_cache
.
_data
elif
scope
==
Scope
.
user_state_summary
:
return
_chunked_query
(
XModuleUserStateSummaryField
,
self
.
select_for_update
,
'usage_id__in'
,
self
.
user_state_summary_cache
=
UserStateSummaryCache
(
self
.
_all_usage_ids
(
descriptors
),
field_name__in
=
set
(
field
.
name
for
field
in
fields
),
fields
,
self
.
select_for_update
,
)
return
self
.
user_state_summary_cache
.
_data
elif
scope
==
Scope
.
preferences
:
return
_chunked_query
(
XModuleStudentPrefsField
,
self
.
select_for_update
,
'module_type__in'
,
self
.
preferences_cache
=
PreferencesCache
(
self
.
user
,
self
.
_all_block_types
(
descriptors
),
student
=
self
.
user
.
pk
,
field_name__in
=
set
(
field
.
name
for
field
in
fields
)
,
fields
,
self
.
select_for_update
,
)
return
self
.
preferences_cache
.
_data
elif
scope
==
Scope
.
user_info
:
return
_query
(
XModuleStudentInfoField
,
self
.
user_info_cache
=
UserInfoCache
(
self
.
user
,
fields
,
self
.
select_for_update
,
student
=
self
.
user
.
pk
,
field_name__in
=
set
(
field
.
name
for
field
in
fields
),
)
return
self
.
user_info_cache
.
_data
else
:
return
[]
...
...
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