Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
edx-platform-release
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
1
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
853a4526
Commit
853a4526
authored
12 years ago
by
Calen Pennington
Browse files
Options
Downloads
Patches
Plain Diff
Use appropriate indexes in mongo modulestore
parent
f0a049a2
No related branches found
Branches containing commit
Tags
release-2021-02-03-12.16
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
common/lib/xmodule/xmodule/modulestore/__init__.py
+4
-0
4 additions, 0 deletions
common/lib/xmodule/xmodule/modulestore/__init__.py
common/lib/xmodule/xmodule/modulestore/mongo.py
+9
-3
9 additions, 3 deletions
common/lib/xmodule/xmodule/modulestore/mongo.py
with
13 additions
and
3 deletions
common/lib/xmodule/xmodule/modulestore/__init__.py
+
4
−
0
View file @
853a4526
...
...
@@ -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
):
...
...
This diff is collapsed.
Click to expand it.
common/lib/xmodule/xmodule/modulestore/mongo.py
+
9
−
3
View file @
853a4526
...
...
@@ -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
)],
...
...
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