Skip to content

Commit

Permalink
Improve memory usage when rebuilding a catalog (#2387)
Browse files Browse the repository at this point in the history
* Deactivate objects after reindexing

* Changelog updated

* Comment changed

---------

Co-authored-by: Jordi Puiggené <jp@naralabs.com>
  • Loading branch information
ramonski and xispa authored Sep 21, 2023
1 parent 4bf470c commit b855997
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
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
- #2389 Added i18n.translate function with multiple domains support
- #2386 Add dynamic search index lookup for referencewidget and added default catalog metadata columns
- #2385 Fix referencefield dependencies in sample add
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

0 comments on commit b855997

Please sign in to comment.