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
1db107c2
Commit
1db107c2
authored
Aug 28, 2014
by
Don Mitchell
Committed by
Andy Armstrong
Aug 29, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add memoization for has_changes
parent
3afc125e
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
34 additions
and
4 deletions
+34
-4
cms/djangoapps/contentstore/views/component.py
+1
-0
cms/djangoapps/contentstore/views/item.py
+1
-1
cms/djangoapps/contentstore/views/tests/test_item.py
+0
-2
common/lib/xmodule/xmodule/modulestore/__init__.py
+31
-0
common/lib/xmodule/xmodule/modulestore/mongo/draft.py
+1
-1
No files found.
cms/djangoapps/contentstore/views/component.py
View file @
1db107c2
...
@@ -28,6 +28,7 @@ from opaque_keys.edx.keys import UsageKey
...
@@ -28,6 +28,7 @@ from opaque_keys.edx.keys import UsageKey
from
.access
import
has_course_access
from
.access
import
has_course_access
from
django.utils.translation
import
ugettext
as
_
from
django.utils.translation
import
ugettext
as
_
from
models.settings.course_grading
import
CourseGradingModel
__all__
=
[
'OPEN_ENDED_COMPONENT_TYPES'
,
__all__
=
[
'OPEN_ENDED_COMPONENT_TYPES'
,
'ADVANCED_COMPONENT_POLICY_KEY'
,
'ADVANCED_COMPONENT_POLICY_KEY'
,
...
...
cms/djangoapps/contentstore/views/item.py
View file @
1db107c2
...
@@ -571,7 +571,7 @@ def _get_xblock(usage_key, user):
...
@@ -571,7 +571,7 @@ def _get_xblock(usage_key, user):
"""
"""
store
=
modulestore
()
store
=
modulestore
()
try
:
try
:
return
store
.
get_item
(
usage_key
)
return
store
.
get_item
(
usage_key
,
depth
=
None
)
except
ItemNotFoundError
:
except
ItemNotFoundError
:
if
usage_key
.
category
in
CREATE_IF_NOT_FOUND
:
if
usage_key
.
category
in
CREATE_IF_NOT_FOUND
:
# Create a new one for certain categories only. Used for course info handouts.
# Create a new one for certain categories only. Used for course info handouts.
...
...
cms/djangoapps/contentstore/views/tests/test_item.py
View file @
1db107c2
"""Tests for items views."""
"""Tests for items views."""
import
os
import
json
import
json
from
datetime
import
datetime
,
timedelta
from
datetime
import
datetime
,
timedelta
import
ddt
import
ddt
from
unittest
import
skipUnless
from
mock
import
patch
from
mock
import
patch
from
pytz
import
UTC
from
pytz
import
UTC
...
...
common/lib/xmodule/xmodule/modulestore/__init__.py
View file @
1db107c2
...
@@ -24,6 +24,7 @@ from opaque_keys import InvalidKeyError
...
@@ -24,6 +24,7 @@ from opaque_keys import InvalidKeyError
from
opaque_keys.edx.locations
import
SlashSeparatedCourseKey
from
opaque_keys.edx.locations
import
SlashSeparatedCourseKey
from
xblock.runtime
import
Mixologist
from
xblock.runtime
import
Mixologist
from
xblock.core
import
XBlock
from
xblock.core
import
XBlock
import
functools
log
=
logging
.
getLogger
(
'edx.modulestore'
)
log
=
logging
.
getLogger
(
'edx.modulestore'
)
...
@@ -559,6 +560,36 @@ class ModuleStoreReadBase(ModuleStoreRead):
...
@@ -559,6 +560,36 @@ class ModuleStoreReadBase(ModuleStoreRead):
raise
ValueError
(
u"Cannot set default store to type {}"
.
format
(
store_type
))
raise
ValueError
(
u"Cannot set default store to type {}"
.
format
(
store_type
))
yield
yield
@staticmethod
def
memoize_request_cache
(
func
):
"""
Memoize a function call results on the request_cache if there's one. Creates the cache key by
joining the unicode of all the args with &; so, if your arg may use the default &, it may
have false hits
"""
@functools.wraps
(
func
)
def
wrapper
(
self
,
*
args
,
**
kwargs
):
if
self
.
request_cache
:
cache_key
=
'&'
.
join
([
hashvalue
(
arg
)
for
arg
in
args
])
if
cache_key
in
self
.
request_cache
.
data
.
setdefault
(
func
.
__name__
,
{}):
return
self
.
request_cache
.
data
[
func
.
__name__
][
cache_key
]
result
=
func
(
self
,
*
args
,
**
kwargs
)
self
.
request_cache
.
data
[
func
.
__name__
][
cache_key
]
=
result
return
result
else
:
return
func
(
self
,
*
args
,
**
kwargs
)
return
wrapper
def
hashvalue
(
arg
):
"""
If arg is an xblock, use its location. otherwise just turn it into a string
"""
if
isinstance
(
arg
,
XBlock
):
return
unicode
(
arg
.
location
)
else
:
return
unicode
(
arg
)
class
ModuleStoreWriteBase
(
ModuleStoreReadBase
,
ModuleStoreWrite
):
class
ModuleStoreWriteBase
(
ModuleStoreReadBase
,
ModuleStoreWrite
):
'''
'''
...
...
common/lib/xmodule/xmodule/modulestore/mongo/draft.py
View file @
1db107c2
...
@@ -589,13 +589,13 @@ class DraftModuleStore(MongoModuleStore):
...
@@ -589,13 +589,13 @@ class DraftModuleStore(MongoModuleStore):
_internal
([
root_usage
.
to_deprecated_son
()
for
root_usage
in
root_usages
])
_internal
([
root_usage
.
to_deprecated_son
()
for
root_usage
in
root_usages
])
self
.
collection
.
remove
({
'_id'
:
{
'$in'
:
to_be_deleted
}},
safe
=
self
.
collection
.
safe
)
self
.
collection
.
remove
({
'_id'
:
{
'$in'
:
to_be_deleted
}},
safe
=
self
.
collection
.
safe
)
@MongoModuleStore.memoize_request_cache
def
has_changes
(
self
,
xblock
):
def
has_changes
(
self
,
xblock
):
"""
"""
Check if the xblock or its children have been changed since the last publish.
Check if the xblock or its children have been changed since the last publish.
:param xblock: xblock to check
:param xblock: xblock to check
:return: True if the draft and published versions differ
:return: True if the draft and published versions differ
"""
"""
# don't check children if this block has changes (is not public)
# don't check children if this block has changes (is not public)
if
self
.
compute_publish_state
(
xblock
)
!=
PublishState
.
public
:
if
self
.
compute_publish_state
(
xblock
)
!=
PublishState
.
public
:
return
True
return
True
...
...
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