Skip to content

Commit

Permalink
Invalidate links on removal and update test
Browse files Browse the repository at this point in the history
  • Loading branch information
keenangraham committed Oct 12, 2020
1 parent d4e9c77 commit 331bdb5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/snovault/invalidation.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ def record_initial_back_revs(event):

@subscriber(Created)
@subscriber(AfterModified)
def invalidate_new_back_revs(event):
def invalidate_changed_back_revs(event):
''' Invalidate objects that rev_link to us
Catch those objects which newly rev_link us
or no longer rev_link us
'''
context = event.object
updated = event.request._updated_uuid_paths
Expand All @@ -57,7 +58,7 @@ def invalidate_new_back_revs(event):
for path in context.type_info.merged_back_rev
}
for rel, uuids in current.items():
for uuid in uuids.difference(initial.get(rel, ())):
for uuid in uuids.symmetric_difference(initial.get(rel, ())):
updated[uuid]


Expand Down
6 changes: 5 additions & 1 deletion src/snovault/tests/test_embedding.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ def test_updated_source(content, testapp):
def test_updated_source_changed(content, testapp):
url = '/testing-link-sources/' + sources[0]['uuid']
res = testapp.patch_json(url, {'target': targets[1]['uuid']})
assert set(res.headers['X-Updated'].split(',')) == {sources[0]['uuid'], targets[1]['uuid']}
assert set(res.headers['X-Updated'].split(',')) == {
sources[0]['uuid'],
targets[0]['uuid'],
targets[1]['uuid'],
}


def test_updated_target(content, testapp):
Expand Down

0 comments on commit 331bdb5

Please sign in to comment.