Commit c59a3db7 by John Eskew

Merge pull request #8537 from edx/jeskew/import_slowdown

Re-nest for the signal-sending, then un-nest.
parents e72eaf81 bd05dc0b
...@@ -272,12 +272,20 @@ class BulkOperationsMixin(object): ...@@ -272,12 +272,20 @@ class BulkOperationsMixin(object):
dirty = self._end_outermost_bulk_operation(bulk_ops_record, structure_key) dirty = self._end_outermost_bulk_operation(bulk_ops_record, structure_key)
self._clear_bulk_ops_record(structure_key) # The bulk op has ended. However, the signal tasks below still need to use the
# built-up bulk op information (if the signals trigger tasks in the same thread).
# So re-nest until the signals are sent.
bulk_ops_record.nest()
if emit_signals and dirty: if emit_signals and dirty:
self.send_bulk_published_signal(bulk_ops_record, structure_key) self.send_bulk_published_signal(bulk_ops_record, structure_key)
self.send_bulk_library_updated_signal(bulk_ops_record, structure_key) self.send_bulk_library_updated_signal(bulk_ops_record, structure_key)
# Signals are sent. Now unnest and clear the bulk op for good.
bulk_ops_record.unnest()
self._clear_bulk_ops_record(structure_key)
def _is_in_bulk_operation(self, course_key, ignore_case=False): def _is_in_bulk_operation(self, course_key, ignore_case=False):
""" """
Return whether a bulk operation is active on `course_key`. Return whether a bulk operation is active on `course_key`.
......
...@@ -2015,8 +2015,11 @@ class TestMixedModuleStore(CommonMixedModuleStoreSetup): ...@@ -2015,8 +2015,11 @@ class TestMixedModuleStore(CommonMixedModuleStoreSetup):
course_key = course.id course_key = course.id
def _clear_bulk_ops_record(course_key): # pylint: disable=unused-argument def _clear_bulk_ops_record(course_key): # pylint: disable=unused-argument
""" Check if the signal has been fired. """ """
self.assertEqual(receiver.call_count, 0) Check if the signal has been fired.
The course_published signal fires before the _clear_bulk_ops_record.
"""
self.assertEqual(receiver.call_count, 1)
with patch.object( with patch.object(
self.store.thread_cache.default_store, '_clear_bulk_ops_record', wraps=_clear_bulk_ops_record self.store.thread_cache.default_store, '_clear_bulk_ops_record', wraps=_clear_bulk_ops_record
......
...@@ -13,6 +13,7 @@ def _generate_course_structure(course_key): ...@@ -13,6 +13,7 @@ def _generate_course_structure(course_key):
""" """
Generates a course structure dictionary for the specified course. Generates a course structure dictionary for the specified course.
""" """
with modulestore().bulk_operations(course_key):
course = modulestore().get_course(course_key, depth=None) course = modulestore().get_course(course_key, depth=None)
blocks_stack = [course] blocks_stack = [course]
blocks_dict = {} blocks_dict = {}
...@@ -27,7 +28,8 @@ def _generate_course_structure(course_key): ...@@ -27,7 +28,8 @@ def _generate_course_structure(course_key):
"children": [unicode(child.scope_ids.usage_id) for child in children] "children": [unicode(child.scope_ids.usage_id) for child in children]
} }
# Retrieve these attributes separately so that we can fail gracefully if the block doesn't have the attribute. # Retrieve these attributes separately so that we can fail gracefully
# if the block doesn't have the attribute.
attrs = (('graded', False), ('format', None)) attrs = (('graded', False), ('format', None))
for attr, default in attrs: for attr, default in attrs:
if hasattr(curr_block, attr): if hasattr(curr_block, attr):
......
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