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

Improve memory usage when rebuilding a catalog #2387

Merged
merged 4 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changelog
2.5.0 (unreleased)
------------------

- #2387 Improve memory usage when rebuilding a catalog
- #2386 Add dynamic search index lookup for referencewidget and added default catalog metadata columns
- #2385 Fix referencefield dependencies in sample add
- #2384 Fix reference widget lookups
Expand Down
12 changes: 12 additions & 0 deletions src/senaite/core/catalog/base_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,18 @@ def log_progress(self):
.format(self.progress_counter, self.id))

if self.progress_counter % 10000 == 0:
logger.info("Creating transaction savepoint after {} objects"
.format(self.progress_counter))
transaction.savepoint(optimistic=True)

def deactivate_object(self, obj):
"""Deactivate the object to save memory
"""
try:
obj._p_deactivate()
except AttributeError:
pass

@security.protected(ManageZCatalogEntries)
def clearFindAndRebuild(self):
"""Considers only mapped types when reindexing the whole catalog
Expand All @@ -176,6 +186,8 @@ def indexObject(obj, path):
if self.is_obj_indexable(obj, portal_type, mapped_types):
self._reindexObject(obj, idxs=idxs) # bypass queue
self.log_progress()
# flush object from memory
self.deactivate_object(obj)
except TypeError:
# Catalogs have 'indexObject' as well, but they
# take different args, and will fail
Expand Down