Reduce the number of queries when walking parents in MongoModuleStore by avoiding cache misses on the data due to missing runs

This commit is contained in:
Calen Pennington
2015-06-09 14:05:01 -04:00
parent 67bde5e2e9
commit e4bc328c3a
2 changed files with 10 additions and 2 deletions

View File

@@ -228,6 +228,14 @@ class CachingDescriptorSystem(MakoDescriptorSystem, EditInfoRuntimeMixin):
Return an XModule instance for the specified location
"""
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)
if json_data is None:
module = self.modulestore.get_item(location, using_descriptor_system=self)
@@ -258,7 +266,7 @@ class CachingDescriptorSystem(MakoDescriptorSystem, EditInfoRuntimeMixin):
else ModuleStoreEnum.Branch.draft_preferred
)
if parent_url:
parent = BlockUsageLocator.from_string(parent_url)
parent = self._convert_reference_to_key(parent_url)
if not parent and category != '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(

View File

@@ -170,7 +170,7 @@ class TestFieldOverrideMongoPerformance(FieldOverridePerformanceTestCase):
(26, 7, 19), (132, 7, 131), (592, 7, 537)
],
'ccx': [
(24, 35, 47), (132, 331, 455), (592, 1507, 2037)
(24, 7, 47), (132, 7, 455), (592, 7, 2037)
],
}