Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-ora2
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-ora2
Commits
0dae41a5
Commit
0dae41a5
authored
Mar 20, 2014
by
David Ormsbee
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add caching for rubric option selection.
parent
ee4dabef
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
8 deletions
+22
-8
apps/openassessment/assessment/models.py
+22
-8
No files found.
apps/openassessment/assessment/models.py
View file @
0dae41a5
...
...
@@ -15,6 +15,7 @@ from copy import deepcopy
from
hashlib
import
sha1
import
json
from
django.core.cache
import
cache
from
django.db
import
models
from
django.utils.timezone
import
now
from
django.utils.translation
import
ugettext
as
_
...
...
@@ -105,17 +106,30 @@ class Rubric(models.Model):
InvalidOptionSelection: the selected options do not match the rubric.
"""
# Select all criteria and options for this rubric
# We use `select_related()` to minimize the number of database queries
rubric_options
=
CriterionOption
.
objects
.
filter
(
criterion__rubric
=
self
)
.
select_related
()
# Create a dict of dicts that maps:
# criterion names --> option names --> option ids
rubric_criteria_dict
=
defaultdict
(
dict
)
rubric_criteria_dict_cache_key
=
(
"assessment.rubric_criteria_dict.{}"
.
format
(
self
.
content_hash
)
)
# If we've already generated one of these for this rubric, grab it from
# the cache instead of hitting the database again.
rubric_criteria_dict
=
cache
.
get
(
rubric_criteria_dict_cache_key
)
if
not
rubric_criteria_dict
:
rubric_criteria_dict
=
defaultdict
(
dict
)
# Select all criteria and options for this rubric
# We use `select_related()` to minimize the number of database queries
rubric_options
=
CriterionOption
.
objects
.
filter
(
criterion__rubric
=
self
)
.
select_related
()
# Construct dictionaries for each option in the rubric
for
option
in
rubric_options
:
rubric_criteria_dict
[
option
.
criterion
.
name
][
option
.
name
]
=
option
.
id
# Construct dictionaries for each option in the rubric
for
option
in
rubric_options
:
rubric_criteria_dict
[
option
.
criterion
.
name
][
option
.
name
]
=
option
.
id
# Save it in our cache
cache
.
set
(
rubric_criteria_dict_cache_key
,
rubric_criteria_dict
)
# Validate: are options selected for each criterion in the rubric?
if
len
(
options_selected
)
!=
len
(
rubric_criteria_dict
):
...
...
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