Skip to content

Commit

Permalink
Merge pull request #21 from zopefoundation/reindex-uid
Browse files Browse the repository at this point in the history
Optimization to only reindex cmf_uid after a UID is set
  • Loading branch information
davisagli authored Jul 17, 2022
2 parents 1812d01 + b88c6cc commit 9f69536
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Products.CMFUid Changelog
3.4 (unreleased)
----------------

- Nothing changed yet.
- When an object is reindexed after its UID is set,
only reindex the ``cmf_uid`` index rather than all indexes.


3.3 (2022-07-13)
Expand Down
12 changes: 6 additions & 6 deletions src/Products/CMFUid/UniqueIdHandlerTool.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,11 @@ class UniqueIdHandlerTool(UniqueObject, SimpleItem):
security = ClassSecurityInfo()

def _reindexObject(self, obj):
ctool = getToolByName(self, 'portal_catalog')
ctool.reindexObject(obj, idxs=[self.UID_ATTRIBUTE_NAME])
try:
obj.reindexObject(idxs=[self.UID_ATTRIBUTE_NAME])
except AttributeError:
ctool = getToolByName(self, 'portal_catalog')
ctool.reindexObject(obj, idxs=[self.UID_ATTRIBUTE_NAME])

def _setUid(self, obj, uid):
"""Attaches a unique id to the object and does reindexing.
Expand All @@ -82,10 +85,7 @@ def _setUid(self, obj, uid):
annotation.setUid(uid)

# reindex the object
try:
obj.reindexObject()
except AttributeError:
self._reindexObject(obj)
self._reindexObject(obj)

security.declarePublic('register')

Expand Down
7 changes: 5 additions & 2 deletions src/Products/CMFUid/tests/test_uidhandling.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,11 @@ def test_UidCatalogingDoesNotCatalogPortalRoot(self):
catalog = self.ctool
dummy = self.app.dummy

# mock the portal root, which has empty indexing attributes
dummy.reindexObject = lambda: None
# An object like the portal root can override
# reindexObject to suppress indexing.
def reindexObject(idxs=[]):
pass
dummy.reindexObject = reindexObject

uid = handler.register(dummy)
brains = catalog(cmf_uid=uid)
Expand Down

0 comments on commit 9f69536

Please sign in to comment.