Commit 81222025 authored by Julien Muchembled's avatar Julien Muchembled

HBTreeFolder2: fix _fixCount(), add dry_run=0 argument

Since commit 055d0a69
("HBTreeFolder2: make object{Ids,Values,Items} really lazy"),
_fixCount() does nothing because objectIds() was optimized in a way that
len(self.objectIds()) already returns self._count()
parent e305f0aa
...@@ -182,10 +182,10 @@ class HBTreeFolder2Base (Persistent): ...@@ -182,10 +182,10 @@ class HBTreeFolder2Base (Persistent):
security.declareProtected(view_management_screens, 'manage_fixCount') security.declareProtected(view_management_screens, 'manage_fixCount')
def manage_fixCount(self): def manage_fixCount(self, dry_run=0):
"""Calls self._fixCount() and reports the result as text. """Calls self._fixCount() and reports the result as text.
""" """
old, new = self._fixCount() old, new = self._fixCount(dry_run)
path = '/'.join(self.getPhysicalPath()) path = '/'.join(self.getPhysicalPath())
if old == new: if old == new:
return "No count mismatch detected in HBTreeFolder2 at %s." % path return "No count mismatch detected in HBTreeFolder2 at %s." % path
...@@ -194,15 +194,14 @@ class HBTreeFolder2Base (Persistent): ...@@ -194,15 +194,14 @@ class HBTreeFolder2Base (Persistent):
"Count was %d; corrected to %d" % (path, old, new)) "Count was %d; corrected to %d" % (path, old, new))
def _fixCount(self): def _fixCount(self, dry_run=0):
"""Checks if the value of self._count disagrees with """Checks if the value of self._count disagrees with the content of
len(self.objectIds()). If so, corrects self._count. Returns the the htree. If so, corrects self._count. Returns the old and new count
old and new count values. If old==new, no correction was values. If old==new, no correction was performed.
performed.
""" """
old = self._count() old = self._count()
new = len(self.objectIds()) new = sum(1 for x in self._htree_iteritems())
if old != new: if old != new and not dry_run:
self._count.set(new) self._count.set(new)
return old, new return old, new
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment