Commit e4bc328c by Calen Pennington

Reduce the number of queries when walking parents in MongoModuleStore by…

Reduce the number of queries when walking parents in MongoModuleStore by avoiding cache misses on the data due to missing runs
parent 67bde5e2
...@@ -228,6 +228,14 @@ class CachingDescriptorSystem(MakoDescriptorSystem, EditInfoRuntimeMixin): ...@@ -228,6 +228,14 @@ class CachingDescriptorSystem(MakoDescriptorSystem, EditInfoRuntimeMixin):
Return an XModule instance for the specified location Return an XModule instance for the specified location
""" """
assert isinstance(location, UsageKey) assert isinstance(location, UsageKey)
if location.run is None:
# self.module_data is keyed on locations that have full run information.
# If the supplied location is missing a run, then we will miss the cache and
# incur an additional query.
# TODO: make module_data a proper class that can handle this itself.
location = location.replace(course_key=self.modulestore.fill_in_run(location.course_key))
json_data = self.module_data.get(location) json_data = self.module_data.get(location)
if json_data is None: if json_data is None:
module = self.modulestore.get_item(location, using_descriptor_system=self) module = self.modulestore.get_item(location, using_descriptor_system=self)
...@@ -258,7 +266,7 @@ class CachingDescriptorSystem(MakoDescriptorSystem, EditInfoRuntimeMixin): ...@@ -258,7 +266,7 @@ class CachingDescriptorSystem(MakoDescriptorSystem, EditInfoRuntimeMixin):
else ModuleStoreEnum.Branch.draft_preferred else ModuleStoreEnum.Branch.draft_preferred
) )
if parent_url: if parent_url:
parent = BlockUsageLocator.from_string(parent_url) parent = self._convert_reference_to_key(parent_url)
if not parent and category != 'course': if not parent and category != 'course':
# try looking it up just-in-time (but not if we're working with a root node (course). # try looking it up just-in-time (but not if we're working with a root node (course).
parent = self.modulestore.get_parent_location( parent = self.modulestore.get_parent_location(
......
...@@ -170,7 +170,7 @@ class TestFieldOverrideMongoPerformance(FieldOverridePerformanceTestCase): ...@@ -170,7 +170,7 @@ class TestFieldOverrideMongoPerformance(FieldOverridePerformanceTestCase):
(26, 7, 19), (132, 7, 131), (592, 7, 537) (26, 7, 19), (132, 7, 131), (592, 7, 537)
], ],
'ccx': [ 'ccx': [
(24, 35, 47), (132, 331, 455), (592, 1507, 2037) (24, 7, 47), (132, 7, 455), (592, 7, 2037)
], ],
} }
......
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