From e4bc328c3a39442fe3eec525fc1624099db391c2 Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Tue, 9 Jun 2015 14:05:01 -0400 Subject: [PATCH] Reduce the number of queries when walking parents in MongoModuleStore by avoiding cache misses on the data due to missing runs --- common/lib/xmodule/xmodule/modulestore/mongo/base.py | 10 +++++++++- .../ccx/tests/test_field_override_performance.py | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/common/lib/xmodule/xmodule/modulestore/mongo/base.py b/common/lib/xmodule/xmodule/modulestore/mongo/base.py index 1e19bf805e..829dad0489 100644 --- a/common/lib/xmodule/xmodule/modulestore/mongo/base.py +++ b/common/lib/xmodule/xmodule/modulestore/mongo/base.py @@ -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( diff --git a/lms/djangoapps/ccx/tests/test_field_override_performance.py b/lms/djangoapps/ccx/tests/test_field_override_performance.py index f33bd40b78..6d142015c8 100644 --- a/lms/djangoapps/ccx/tests/test_field_override_performance.py +++ b/lms/djangoapps/ccx/tests/test_field_override_performance.py @@ -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) ], }