From 5732dc835552194170d35a3e8485de4155b54220 Mon Sep 17 00:00:00 2001 From: Michel Pelletier Date: Wed, 30 Jun 1999 20:36:22 +0000 Subject: [PATCH] Improved handling of subtransactions. Should keep memory from ballooning beyong the capacity of the machine. Note: while mass indexing, the memory footprint of Zope will get huge. There is NO way around this. incrimentally index if you want your process to stay small. --- Catalog.py | 4 ++-- ZCatalog.py | 24 +++++++++++++++++++----- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/Catalog.py b/Catalog.py index 457680ce..37ff465c 100644 --- a/Catalog.py +++ b/Catalog.py @@ -274,7 +274,7 @@ def delIndex(self, name): # the cataloging API - def catalogObject(self, object, uid): + def catalogObject(self, object, uid, threshold=None): """ Adds an object to the Catalog by iteratively applying it @@ -304,7 +304,7 @@ def catalogObject(self, object, uid): total = 0 for x in self.indexes.values(): if hasattr(x, 'index_object'): - blah = x.index_object(i, object) + blah = x.index_object(i, object, threshold) __traceback_info__=(`total`, `blah`) total = total + blah diff --git a/ZCatalog.py b/ZCatalog.py index 398ac609..e0e7562c 100644 --- a/ZCatalog.py +++ b/ZCatalog.py @@ -159,7 +159,7 @@ def __init__(self,id,title=None): self.id=id self.title=title self.threshold = 1000 - self.total = 0 + self._v_total = 0 self._catalog = Catalog() self._catalog.addColumn('id') @@ -176,7 +176,17 @@ def __init__(self,id,title=None): self._catalog.addColumn('summary') self._catalog.addIndex('PrincipiaSearchSource', 'TextIndex') + + + def manage_edit(self, threshold=1000, REQUEST=None): + """ edit the catalog """ + self.threshold = threshold + + message = "Object changed" + return self.manage_main(self, REQUEST, + manage_tabs_message=message) + def manage_catalogObject(self, REQUEST, urls=None, blah=None): """ index all Zope objects that 'urls' point to """ @@ -251,7 +261,6 @@ def manage_catalogFoundItems(self, REQUEST, obj_metatypes=None, """ Find object according to search criteria and Catalog them """ - results = self.ZopeFind(REQUEST.PARENTS[1], obj_metatypes=obj_metatypes, obj_ids=obj_ids, @@ -309,10 +318,15 @@ def manage_delIndexes(self, names, REQUEST): def catalog_object(self, obj, uid): """ wrapper around catalog """ - self.total = self.total + self._catalog.catalogObject(obj, uid) - if self.total > self.threshold: + if not hasattr(self, '_v_total'): + self._v_total = 0 + self._v_total = (self._v_total + + self._catalog.catalogObject(obj, uid, self.threshold)) + + if self._v_total > self.threshold: + print 'commiting in ZCatalog' get_transaction().commit(1) - self.total = 0 + self._v_total = 0 def uncatalog_object(self, uid):