Skip to content

Commit

Permalink
Remove old index entries when path changes
Browse files Browse the repository at this point in the history
  • Loading branch information
andbag committed Apr 17, 2019
1 parent d061593 commit 5a87b4a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Expand Up @@ -26,6 +26,10 @@ Bug fixes
many indexed objects
(`#39 <https://github.com/zopefoundation/Products.ZCatalog/issues/39>`_)

- Make sure ``PathIndex._index_object`` removes old index entries
when path of object changes
(`#61 <https://github.com/zopefoundation/Products.ZCatalog/issues/61>`_)


4.4 (2019-03-08)
----------------
Expand Down
6 changes: 4 additions & 2 deletions src/Products/PluginIndexes/PathIndex/PathIndex.py
Expand Up @@ -123,8 +123,10 @@ def index_object(self, docid, obj, threshold=100):
if old_value == path:
return 0

if old_value is None:
self._length.change(1)
if old_value:
self.unindex_object(docid)

self._length.change(1)

for i in range(len(comps)):
self.insertEntry(comps[i], docid, i)
Expand Down
15 changes: 15 additions & 0 deletions src/Products/PluginIndexes/PathIndex/tests.py
Expand Up @@ -367,6 +367,21 @@ def test__apply_index_QueryPathReturnedInResult(self):
lst = list(res[0].keys())
self.assertEqual(lst, [2, 3, 4])

def test__apply_index_when_path_changes(self):
index = self._makeOne()
doc = Dummy('/aa')
index.index_object(0, doc)
res = index._apply_index(dict(path='aa'))
self.assertEqual(list(res[0].keys()), [0])

doc.path = '/bb'
index.index_object(0, doc)
res = index._apply_index(dict(path='bb'))
self.assertEqual(list(res[0].keys()), [0])

res = index._apply_index(dict(path='aa'))
self.assertEqual(list(res[0].keys()), [])

def test_numObjects_empty(self):
index = self._makeOne()
self.assertEqual(index.numObjects(), 0)
Expand Down

0 comments on commit 5a87b4a

Please sign in to comment.