Skip to content

Commit

Permalink
Add getCounter logic
Browse files Browse the repository at this point in the history
  • Loading branch information
andbag committed Sep 1, 2016
1 parent d7d5309 commit 9cad89a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/Products/ZCatalog/ZCatalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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')
Expand Down
12 changes: 12 additions & 0 deletions src/Products/ZCatalog/tests/test_zcatalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9cad89a

Please sign in to comment.