Commit c0616aeb by Calen Pennington

Remove unneccesary uses of SON (which is slower than dict)

parent a72cbfe6
from opaque_keys.edx.locator import DefinitionLocator from opaque_keys.edx.locator import DefinitionLocator
from bson import SON
class DefinitionLazyLoader(object): class DefinitionLazyLoader(object):
...@@ -25,9 +24,3 @@ class DefinitionLazyLoader(object): ...@@ -25,9 +24,3 @@ class DefinitionLazyLoader(object):
loader pointer with the result so as not to fetch more than once loader pointer with the result so as not to fetch more than once
""" """
return self.modulestore.db_connection.get_definition(self.definition_locator.definition_id) return self.modulestore.db_connection.get_definition(self.definition_locator.definition_id)
def as_son(self):
return SON((
('block_type', self.definition_locator.block_type),
('definition', self.definition_locator.definition_id)
))
...@@ -82,7 +82,6 @@ class MongoConnection(object): ...@@ -82,7 +82,6 @@ class MongoConnection(object):
host=host, host=host,
port=port, port=port,
tz_aware=tz_aware, tz_aware=tz_aware,
document_class=son.SON,
**kwargs **kwargs
), ),
db db
...@@ -167,10 +166,10 @@ class MongoConnection(object): ...@@ -167,10 +166,10 @@ class MongoConnection(object):
""" """
case_regex = ur"(?i)^{}$" if ignore_case else ur"{}" case_regex = ur"(?i)^{}$" if ignore_case else ur"{}"
return self.course_index.find_one( return self.course_index.find_one(
son.SON([ {
(key_attr, re.compile(case_regex.format(getattr(key, key_attr)))) key_attr: re.compile(case_regex.format(getattr(key, key_attr)))
for key_attr in ('org', 'course', 'run') for key_attr in ('org', 'course', 'run')
]) }
) )
def find_matching_course_indexes(self, branch=None, search_targets=None): def find_matching_course_indexes(self, branch=None, search_targets=None):
...@@ -182,7 +181,7 @@ class MongoConnection(object): ...@@ -182,7 +181,7 @@ class MongoConnection(object):
search_targets: If specified, this must be a dictionary specifying field values search_targets: If specified, this must be a dictionary specifying field values
that must exist in the search_targets of the returned courses that must exist in the search_targets of the returned courses
""" """
query = son.SON() query = {}
if branch is not None: if branch is not None:
query['versions.{}'.format(branch)] = {'$exists': True} query['versions.{}'.format(branch)] = {'$exists': True}
...@@ -206,11 +205,11 @@ class MongoConnection(object): ...@@ -206,11 +205,11 @@ class MongoConnection(object):
from_index: If set, only update an index if it matches the one specified in `from_index`. from_index: If set, only update an index if it matches the one specified in `from_index`.
""" """
self.course_index.update( self.course_index.update(
from_index or son.SON([ from_index or {
('org', course_index['org']), 'org': course_index['org'],
('course', course_index['course']), 'course': course_index['course'],
('run', course_index['run']) 'run': course_index['run'],
]), },
course_index, course_index,
upsert=False, upsert=False,
) )
...@@ -219,11 +218,11 @@ class MongoConnection(object): ...@@ -219,11 +218,11 @@ class MongoConnection(object):
""" """
Delete the course_index from the persistence mechanism whose id is the given course_index Delete the course_index from the persistence mechanism whose id is the given course_index
""" """
return self.course_index.remove(son.SON([ return self.course_index.remove({
('org', course_index['org']), 'org': course_index['org'],
('course', course_index['course']), 'course': course_index['course'],
('run', course_index['run']) 'run': course_index['run'],
])) })
def get_definition(self, key): def get_definition(self, key):
""" """
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment