Commit a205788c by Calen Pennington

Work around for split not having a coherent way to work with/track updated versions of structures

parent e624ff3b
...@@ -208,8 +208,6 @@ class TemplateTests(unittest.TestCase): ...@@ -208,8 +208,6 @@ class TemplateTests(unittest.TestCase):
# The draft course root has 2 revisions: the published revision, and then the subsequent # The draft course root has 2 revisions: the published revision, and then the subsequent
# changes to the draft revision # changes to the draft revision
version_history = self.split_store.get_block_generations(test_course.location) version_history = self.split_store.get_block_generations(test_course.location)
# Base calculations on the draft revision, not the initial published revision
version_history = version_history.children[0]
self.assertEqual(version_history.locator.version_guid, test_course.location.version_guid) self.assertEqual(version_history.locator.version_guid, test_course.location.version_guid)
self.assertEqual(len(version_history.children), 1) self.assertEqual(len(version_history.children), 1)
self.assertEqual(version_history.children[0].children, []) self.assertEqual(version_history.children[0].children, [])
......
...@@ -67,13 +67,16 @@ class SplitMigrator(object): ...@@ -67,13 +67,16 @@ class SplitMigrator(object):
**kwargs **kwargs
) )
with self.split_modulestore.bulk_write_operations(new_course.id): self._copy_published_modules_to_course(
self._copy_published_modules_to_course( new_course, original_course.location, source_course_key, user_id, **kwargs
new_course, original_course.location, source_course_key, user_id, **kwargs )
)
# TODO: This should be merged back into the above transaction, but can't be until split.py
# is refactored to have more coherent access patterns
with self.split_modulestore.bulk_write_operations(new_course_key):
# create a new version for the drafts # create a new version for the drafts
self._add_draft_modules_to_course(new_course.location, source_course_key, user_id, **kwargs) self._add_draft_modules_to_course(new_course.location, source_course_key, user_id, **kwargs)
return new_course.id return new_course.id
...@@ -81,7 +84,7 @@ class SplitMigrator(object): ...@@ -81,7 +84,7 @@ class SplitMigrator(object):
""" """
Copy all of the modules from the 'direct' version of the course to the new split course. Copy all of the modules from the 'direct' version of the course to the new split course.
""" """
course_version_locator = new_course.id course_version_locator = new_course.id.replace(version_guid=None)
# iterate over published course elements. Wildcarding rather than descending b/c some elements are orphaned (e.g., # iterate over published course elements. Wildcarding rather than descending b/c some elements are orphaned (e.g.,
# course about pages, conditionals) # course about pages, conditionals)
......
...@@ -113,10 +113,6 @@ class BulkWriteRecord(object): ...@@ -113,10 +113,6 @@ class BulkWriteRecord(object):
self.structures = {} self.structures = {}
self.structures_in_db = set() self.structures_in_db = set()
# This stores the set of branches for whom version_structure
# has been called
self.dirty_branches = set()
@property @property
def active(self): def active(self):
""" """
...@@ -143,13 +139,37 @@ class BulkWriteRecord(object): ...@@ -143,13 +139,37 @@ class BulkWriteRecord(object):
""" """
return self._active_count == 1 return self._active_count == 1
# TODO: This needs to track which branches have actually been modified/versioned,
# so that copying one branch to another doesn't update the original branch.
@property
def dirty_branches(self):
"""
Return a list of which branch version ids differ from what was stored
in the database at the beginning of this bulk operation.
"""
# If no course index has been set, then no branches have changed
if self.index is None:
return []
# If there was no index in the database to start with, then all branches
# are dirty by definition
if self.initial_index is None:
return self.index.get('versions', {}).keys()
# Return branches whose ids differ between self.index and self.initial_index
return [
branch
for branch, _id
in self.index.get('versions', {}).items()
if self.initial_index.get('versions', {}).get(branch) != _id
]
def structure_for_branch(self, branch): def structure_for_branch(self, branch):
return self.structures.get(self.index.get('versions', {}).get(branch)) return self.structures.get(self.index.get('versions', {}).get(branch))
def set_structure_for_branch(self, branch, structure): def set_structure_for_branch(self, branch, structure):
self.index.get('versions', {})[branch] = structure['_id'] self.index.get('versions', {})[branch] = structure['_id']
self.structures[structure['_id']] = structure self.structures[structure['_id']] = structure
self.dirty_branches.add(branch)
def __repr__(self): def __repr__(self):
return u"BulkWriteRecord<{!r}, {!r}, {!r}, {!r}, {!r}>".format( return u"BulkWriteRecord<{!r}, {!r}, {!r}, {!r}, {!r}>".format(
......
...@@ -714,10 +714,10 @@ class TestMixedModuleStore(unittest.TestCase): ...@@ -714,10 +714,10 @@ class TestMixedModuleStore(unittest.TestCase):
# - load vertical # - load vertical
# - load inheritance data # - load inheritance data
# TODO: LMS-11220: Document why draft send count is 5 # TODO: LMS-11220: Document why draft send count is 6
# TODO: LMS-11220: Document why draft find count is 18 # TODO: LMS-11220: Document why draft find count is 18
# TODO: LMS-11220: Document why split find count is 16 # TODO: LMS-11220: Document why split find count is 16
@ddt.data(('draft', [19, 5], 0), ('split', [2, 2], 0)) @ddt.data(('draft', [19, 6], 0), ('split', [2, 2], 0))
@ddt.unpack @ddt.unpack
def test_path_to_location(self, default_ms, num_finds, num_sends): def test_path_to_location(self, default_ms, num_finds, num_sends):
""" """
......
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