From 0e6bc21019e9e403a1d128b8c2b195747fd85d63 Mon Sep 17 00:00:00 2001 From: John Eskew Date: Fri, 6 Feb 2015 15:43:39 -0500 Subject: [PATCH] Add missing caching for SplitBulkWriteMixin:get_definitions(). If a particular depth is requested, override lazy definition loading. --- .../xmodule/xmodule/modulestore/split_mongo/split.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/common/lib/xmodule/xmodule/modulestore/split_mongo/split.py b/common/lib/xmodule/xmodule/modulestore/split_mongo/split.py index 324f317698..73ae73f625 100644 --- a/common/lib/xmodule/xmodule/modulestore/split_mongo/split.py +++ b/common/lib/xmodule/xmodule/modulestore/split_mongo/split.py @@ -402,13 +402,18 @@ class SplitBulkWriteMixin(BulkOperationsMixin): bulk_write_record = self._get_bulk_ops_record(course_key) if bulk_write_record.active: + # Only query for the definitions that aren't already cached. for definition in bulk_write_record.definitions.values(): definition_id = definition.get('_id') if definition_id in ids: ids.remove(definition_id) definitions.append(definition) - definitions.extend(self.db_connection.get_definitions(list(ids))) + # Query the db for the definitions. + defs_from_db = self.db_connection.get_definitions(list(ids)) + # Add the retrieved definitions to the cache. + bulk_write_record.definitions.update({d.get('_id'): d for d in defs_from_db}) + definitions.extend(defs_from_db) return definitions def update_definition(self, course_key, definition): @@ -688,7 +693,7 @@ class SplitMongoModuleStore(SplitBulkWriteMixin, ModuleStoreWriteBase): descendent_definitions = self.get_definitions( course_key, [ - block['definition'] + block.definition for block in new_module_data.itervalues() ] ) @@ -718,7 +723,7 @@ class SplitMongoModuleStore(SplitBulkWriteMixin, ModuleStoreWriteBase): if runtime is None: runtime = self.create_runtime(course_entry, lazy) self._add_cache(course_entry.structure['_id'], runtime) - self.cache_items(runtime, block_keys, course_entry.course_key, depth, lazy) + self.cache_items(runtime, block_keys, course_entry.course_key, depth, depth == 0 and lazy) return [runtime.load_item(block_key, course_entry, **kwargs) for block_key in block_keys]