Commit 4131f867 by Christina Roberts

Merge pull request #1694 from MITx/fix/cdodge/disable-metadata-inheritence-computation-on-import

add an array of courses to not refresh the metadata cache on writes. Thi...
parents e4437b7a 5dbb153a
...@@ -246,6 +246,7 @@ class MongoModuleStore(ModuleStoreBase): ...@@ -246,6 +246,7 @@ class MongoModuleStore(ModuleStoreBase):
self.fs_root = path(fs_root) self.fs_root = path(fs_root)
self.error_tracker = error_tracker self.error_tracker = error_tracker
self.render_template = render_template self.render_template = render_template
self.ignore_write_events_on_courses = []
def get_metadata_inheritance_tree(self, location): def get_metadata_inheritance_tree(self, location):
''' '''
...@@ -330,6 +331,11 @@ class MongoModuleStore(ModuleStoreBase): ...@@ -330,6 +331,11 @@ class MongoModuleStore(ModuleStoreBase):
return tree return tree
def refresh_cached_metadata_inheritance_tree(self, location):
pseudo_course_id = '/'.join([location.org, location.course])
if pseudo_course_id not in self.ignore_write_events_on_courses:
self.get_cached_metadata_inheritance_tree(location, force_refresh = True)
def clear_cached_metadata_inheritance_tree(self, location): def clear_cached_metadata_inheritance_tree(self, location):
key_name = '{0}/{1}'.format(location.org, location.course) key_name = '{0}/{1}'.format(location.org, location.course)
if self.metadata_inheritance_cache is not None: if self.metadata_inheritance_cache is not None:
...@@ -520,7 +526,7 @@ class MongoModuleStore(ModuleStoreBase): ...@@ -520,7 +526,7 @@ class MongoModuleStore(ModuleStoreBase):
raise DuplicateItemError(location) raise DuplicateItemError(location)
# recompute (and update) the metadata inheritance tree which is cached # recompute (and update) the metadata inheritance tree which is cached
self.get_cached_metadata_inheritance_tree(Location(location), force_refresh = True) self.refresh_cached_metadata_inheritance_tree(Location(location))
def get_course_for_item(self, location, depth=0): def get_course_for_item(self, location, depth=0):
''' '''
...@@ -590,7 +596,7 @@ class MongoModuleStore(ModuleStoreBase): ...@@ -590,7 +596,7 @@ class MongoModuleStore(ModuleStoreBase):
self._update_single_item(location, {'definition.children': children}) self._update_single_item(location, {'definition.children': children})
# recompute (and update) the metadata inheritance tree which is cached # recompute (and update) the metadata inheritance tree which is cached
self.get_cached_metadata_inheritance_tree(Location(location), force_refresh = True) self.refresh_cached_metadata_inheritance_tree(Location(location))
def update_metadata(self, location, metadata): def update_metadata(self, location, metadata):
""" """
...@@ -616,7 +622,7 @@ class MongoModuleStore(ModuleStoreBase): ...@@ -616,7 +622,7 @@ class MongoModuleStore(ModuleStoreBase):
self._update_single_item(location, {'metadata': metadata}) self._update_single_item(location, {'metadata': metadata})
# recompute (and update) the metadata inheritance tree which is cached # recompute (and update) the metadata inheritance tree which is cached
self.get_cached_metadata_inheritance_tree(loc, force_refresh = True) self.refresh_cached_metadata_inheritance_tree(loc)
def delete_item(self, location): def delete_item(self, location):
""" """
...@@ -639,8 +645,7 @@ class MongoModuleStore(ModuleStoreBase): ...@@ -639,8 +645,7 @@ class MongoModuleStore(ModuleStoreBase):
# from overriding our default value set in the init method. # from overriding our default value set in the init method.
safe=self.collection.safe) safe=self.collection.safe)
# recompute (and update) the metadata inheritance tree which is cached # recompute (and update) the metadata inheritance tree which is cached
self.get_cached_metadata_inheritance_tree(Location(location), force_refresh = True) self.refresh_cached_metadata_inheritance_tree(Location(location))
def get_parent_locations(self, location, course_id): def get_parent_locations(self, location, course_id):
'''Find all locations that are the parents of this location in this '''Find all locations that are the parents of this location in this
......
...@@ -201,6 +201,17 @@ def import_from_xml(store, data_dir, course_dirs=None, ...@@ -201,6 +201,17 @@ def import_from_xml(store, data_dir, course_dirs=None,
course_items = [] course_items = []
for course_id in module_store.modules.keys(): for course_id in module_store.modules.keys():
if target_location_namespace is not None:
pseudo_course_id = '/'.join([target_location_namespace.org, target_location_namespace.course])
else:
course_id_components = course_id.split('/')
pseudo_course_id = '/'.join([course_id_components[0], course_id_components[1]])
try:
# turn off all write signalling while importing as this is a high volume operation
if pseudo_course_id not in store.ignore_write_events_on_courses:
store.ignore_write_events_on_courses.append(pseudo_course_id)
course_data_path = None course_data_path = None
course_location = None course_location = None
...@@ -295,6 +306,12 @@ def import_from_xml(store, data_dir, course_dirs=None, ...@@ -295,6 +306,12 @@ def import_from_xml(store, data_dir, course_dirs=None,
# NOTE: It's important to use own_metadata here to avoid writing # NOTE: It's important to use own_metadata here to avoid writing
# inherited metadata everywhere. # inherited metadata everywhere.
store.update_metadata(module.location, dict(own_metadata(module))) store.update_metadata(module.location, dict(own_metadata(module)))
finally:
# turn back on all write signalling
if pseudo_course_id in store.ignore_write_events_on_courses:
store.ignore_write_events_on_courses.remove(pseudo_course_id)
store.refresh_cached_metadata_inheritance_tree(target_location_namespace if
target_location_namespace is not None else course_location)
return module_store, course_items return module_store, course_items
......
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