Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimization to only reindex cmf_uid after a UID is set #21

Merged
merged 1 commit into from
Jul 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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