diff --git a/src/Products/ZCatalog/ZCatalog.py b/src/Products/ZCatalog/ZCatalog.py index 45be603a..618f2711 100644 --- a/src/Products/ZCatalog/ZCatalog.py +++ b/src/Products/ZCatalog/ZCatalog.py @@ -30,6 +30,7 @@ from Acquisition import aq_parent from Acquisition import Implicit from App.special_dtml import DTMLFile +from BTrees.Length import Length from DateTime.DateTime import DateTime from DocumentTemplate.DT_Util import InstanceDict from DocumentTemplate.DT_Util import TemplateDict @@ -159,6 +160,8 @@ class is that it is not Zope specific. You can use it in any _v_total = 0 _v_transaction = None + _counter = None + def __init__(self, id, title='', vocab_id=None, container=None): # ZCatalog no longer cares about vocabularies # so the vocab_id argument is ignored (Casey) @@ -290,6 +293,8 @@ def refreshCatalog(self, clear=0, pghandler=None): security.declareProtected(manage_zcatalog_entries, 'manage_catalogClear') def manage_catalogClear(self, REQUEST=None, RESPONSE=None, URL1=None): """ clears the whole enchilada """ + + self._increment_counter() self._catalog.clear() if REQUEST and RESPONSE: @@ -484,6 +489,9 @@ def maintain_zodb_cache(self): security.declareProtected(manage_zcatalog_entries, 'catalog_object') def catalog_object(self, obj, uid=None, idxs=None, update_metadata=1, pghandler=None): + + self._increment_counter() + if uid is None: try: uid = obj.getPhysicalPath @@ -511,8 +519,18 @@ def catalog_object(self, obj, uid=None, idxs=None, update_metadata=1, security.declareProtected(manage_zcatalog_entries, 'uncatalog_object') def uncatalog_object(self, uid): + self._increment_counter() self._catalog.uncatalogObject(uid) + def _increment_counter(self): + if self._counter is None: + self._counter = Length() + self._counter.change(1) + + security.declarePrivate('getCounter') + def getCounter(self): + return self._counter is not None and self._counter() or 0 + security.declareProtected(search_zcatalog, 'uniqueValuesFor') def uniqueValuesFor(self, name): # Return the unique values for a given FieldIndex @@ -819,6 +837,7 @@ def _getProgressThreshold(self): security.declareProtected(manage_zcatalog_indexes, 'addIndex') def addIndex(self, name, type, extra=None): if IPluggableIndex.providedBy(type): + self._increment_counter() self._catalog.addIndex(name, type) return @@ -854,14 +873,17 @@ def addIndex(self, name, type, extra=None): else: index = base(name) + self._increment_counter() self._catalog.addIndex(name, index) security.declareProtected(manage_zcatalog_indexes, 'delIndex') def delIndex(self, name): + self._increment_counter() self._catalog.delIndex(name) security.declareProtected(manage_zcatalog_indexes, 'clearIndex') def clearIndex(self, name): + self._increment_counter() self._catalog.getIndex(name).clear() security.declareProtected(manage_zcatalog_indexes, 'addColumn') diff --git a/src/Products/ZCatalog/tests/test_zcatalog.py b/src/Products/ZCatalog/tests/test_zcatalog.py index 5f246125..0f3ab4cc 100644 --- a/src/Products/ZCatalog/tests/test_zcatalog.py +++ b/src/Products/ZCatalog/tests/test_zcatalog.py @@ -211,6 +211,18 @@ def testReindexIndexesFalse(self): # manage_reindexIndex # catalog_object # uncatalog_object + + def test_getcounter(self): + counter = self._catalog.getCounter() + + self._catalog.catalog_object(ZDummy(1), 'xyz123') + counter_1 = self._catalog.getCounter() + self.assertEquals(counter + 1, counter_1) + + self._catalog.uncatalog_object('xyz123') + counter_2 = self._catalog.getCounter() + self.assertEquals(counter_1 + 1, counter_2) + # uniqueValuesFor # getpath # getrid