Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
edx-platform-release
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hsin-Yu Chien
edx-platform-release
Commits
d60d6896
Commit
d60d6896
authored
13 years ago
by
David Ormsbee
Browse files
Options
Downloads
Plain Diff
Merge performance fixes, and rename StudentModule.get_from_cache to get_with_caching
parents
7f68610d
ab0b7910
Loading
Loading
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
courseware/content_parser.py
+12
-6
12 additions, 6 deletions
courseware/content_parser.py
courseware/models.py
+38
-1
38 additions, 1 deletion
courseware/models.py
courseware/module_render.py
+4
-4
4 additions, 4 deletions
courseware/module_render.py
with
54 additions
and
11 deletions
courseware/content_parser.py
+
12
−
6
View file @
d60d6896
...
...
@@ -168,17 +168,23 @@ def course_xml_process(tree):
return
tree
def
course_file
(
user
):
'''
Given a user, return course.xml
'''
# TODO: Cache.
'''
Given a user, return course.xml
'''
filename
=
user
.
profile_cache
.
courseware
# UserProfile.objects.get(user=user).courseware
groups
=
user_groups
(
user
)
options
=
{
'
dev_content
'
:
settings
.
DEV_CONTENT
,
'
groups
'
:
groups
}
tree
=
course_xml_process
(
etree
.
XML
(
render_to_string
(
filename
,
options
,
namespace
=
'
course
'
)))
cache_key
=
filename
+
"
_processed?dev_content:
"
+
str
(
options
[
'
dev_content
'
])
+
"
&groups:
"
+
str
(
sorted
(
groups
))
tree_string
=
cache
.
get
(
cache_key
)
if
not
tree_string
:
tree
=
course_xml_process
(
etree
.
XML
(
render_to_string
(
filename
,
options
,
namespace
=
'
course
'
)))
tree_string
=
etree
.
tostring
(
tree
)
cache
.
set
(
cache_key
,
tree_string
,
60
)
else
:
tree
=
etree
.
XML
(
tree_string
)
return
tree
def
section_file
(
user
,
section
):
...
...
This diff is collapsed.
Click to expand it.
courseware/models.py
+
38
−
1
View file @
d60d6896
...
...
@@ -8,12 +8,19 @@ file and check it in at the same time as your model changes. To do that,
2. ./manage.py schemamigration courseware --auto description_of_your_change
3. Add the migration file created in mitx/courseware/migrations/
ASSUMPTIONS: modules have unique IDs, even across different module_types
"""
from
django.db
import
models
from
django.db.models.signals
import
post_save
,
post_delete
from
django.core.cache
import
cache
from
django.contrib.auth.models
import
User
from
cache_toolbox
import
cache_model
,
cache_relation
CACHE_TIMEOUT
=
60
*
60
*
4
# Set the cache timeout to be four hours
class
StudentModule
(
models
.
Model
):
# For a homework problem, contains a JSON
# object consisting of state
...
...
@@ -51,5 +58,35 @@ class StudentModule(models.Model):
def
__unicode__
(
self
):
return
self
.
module_type
+
'
/
'
+
self
.
student
.
username
+
"
/
"
+
self
.
module_id
+
'
/
'
+
str
(
self
.
state
)[:
20
]
@classmethod
def
get_with_caching
(
cls
,
student
,
module_id
):
k
=
cls
.
key_for
(
student
,
module_id
)
student_module
=
cache
.
get
(
k
)
if
student_module
is
None
:
student_module
=
StudentModule
.
objects
.
filter
(
student
=
student
,
module_id
=
module_id
)[
0
]
# It's possible it really doesn't exist...
if
student_module
is
not
None
:
cache
.
set
(
k
,
student_module
,
CACHE_TIMEOUT
)
return
student_module
@classmethod
def
key_for
(
cls
,
student
,
module_id
):
return
"
StudentModule-student_id:{0};module_id:{1}
"
.
format
(
student
.
id
,
module_id
)
def
clear_cache_by_student_and_module_id
(
sender
,
instance
,
*
args
,
**
kwargs
):
k
=
sender
.
key_for
(
instance
.
student
,
instance
.
module_id
)
cache
.
delete
(
k
)
def
update_cache_by_student_and_module_id
(
sender
,
instance
,
*
args
,
**
kwargs
):
k
=
sender
.
key_for
(
instance
.
student
,
instance
.
module_id
)
cache
.
set
(
k
,
instance
,
CACHE_TIMEOUT
)
post_save
.
connect
(
update_cache_by_student_and_module_id
,
sender
=
StudentModule
,
weak
=
False
)
post_delete
.
connect
(
clear_cache_by_student_and_module_id
,
sender
=
StudentModule
,
weak
=
False
)
cache_model
(
StudentModule
)
cache_model
(
StudentModule
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
courseware/module_render.py
+
4
−
4
View file @
d60d6896
...
...
@@ -48,13 +48,13 @@ def make_track_function(request):
def
modx_dispatch
(
request
,
module
=
None
,
dispatch
=
None
,
id
=
None
):
'''
Generic view for extensions.
'''
# Grab the student information for the module from the database
s
=
StudentModule
.
objects
.
filter
(
student
=
request
.
user
,
module_id
=
id
)
if
len
(
s
)
==
0
:
#s = StudentModule.objects.filter(student=request.user,
# module_id=id)
s
=
StudentModule
.
get_with_caching
(
request
.
user
,
id
)
if
s
is
None
:
log
.
debug
(
"
Couldnt find module for user and id
"
+
str
(
module
)
+
"
"
+
str
(
request
.
user
)
+
"
"
+
str
(
id
))
raise
Http404
s
=
s
[
0
]
oldgrade
=
s
.
grade
oldstate
=
s
.
state
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment