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
3c7e9972
Commit
3c7e9972
authored
Jul 11, 2012
by
Calen Pennington
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use appropriate indexes in mongo modulestore
parent
1b762124
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
3 deletions
+13
-3
common/lib/xmodule/xmodule/modulestore/__init__.py
+4
-0
common/lib/xmodule/xmodule/modulestore/mongo.py
+9
-3
No files found.
common/lib/xmodule/xmodule/modulestore/__init__.py
View file @
3c7e9972
...
...
@@ -128,6 +128,10 @@ class Location(_LocationBase):
return
"-"
.
join
(
str
(
v
)
for
v
in
self
.
list
()
if
v
is
not
None
)
.
replace
(
'.'
,
'_'
)
def
dict
(
self
):
"""
Return an OrderedDict of this locations keys and values. The order is
tag, org, course, category, name, revision
"""
return
self
.
_asdict
()
def
list
(
self
):
...
...
common/lib/xmodule/xmodule/modulestore/mongo.py
View file @
3c7e9972
...
...
@@ -4,18 +4,21 @@ from importlib import import_module
from
xmodule.x_module
import
XModuleDescriptor
from
xmodule.mako_module
import
MakoDescriptorSystem
from
mitxmako.shortcuts
import
render_to_string
from
bson.son
import
SON
from
itertools
import
repeat
from
.
import
ModuleStore
,
Location
from
.exceptions
import
ItemNotFoundError
,
InsufficientSpecificationError
# TODO (cpennington): This code currently operates under the assumption that
# there is only one revision for each item. Once we start versioning inside the CMS,
# that assumption will have to change
def
location_to_query
(
loc
):
query
=
{}
query
=
SON
()
# Location dict is ordered by specificity, and SON
# will preserve that order for queries
for
key
,
val
in
Location
(
loc
)
.
dict
()
.
iteritems
():
if
val
is
not
None
:
query
[
'_id.{key}'
.
format
(
key
=
key
)]
=
val
...
...
@@ -35,6 +38,10 @@ class MongoModuleStore(ModuleStore):
# Force mongo to report errors, at the expense of performance
self
.
collection
.
safe
=
True
# Force mongo to maintain an index over _id.* that is in the same order
# that is used when querying by a location
self
.
collection
.
ensure_index
(
zip
((
'_id.'
+
field
for
field
in
Location
.
_fields
),
repeat
(
1
)))
module_path
,
_
,
class_name
=
default_class
.
rpartition
(
'.'
)
class_
=
getattr
(
import_module
(
module_path
),
class_name
)
self
.
default_class
=
class_
...
...
@@ -77,7 +84,6 @@ class MongoModuleStore(ModuleStore):
return
self
.
_load_item
(
item
)
def
get_items
(
self
,
location
,
default_class
=
None
):
print
location_to_query
(
location
)
items
=
self
.
collection
.
find
(
location_to_query
(
location
),
sort
=
[(
'revision'
,
pymongo
.
ASCENDING
)],
...
...
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