Commit e22ce2fb authored by Andreas Jung's avatar Andreas Jung

removed __len__ as persistent attribute

parent c6a56330
...@@ -88,30 +88,16 @@ class UnIndex(SimpleItem): ...@@ -88,30 +88,16 @@ class UnIndex(SimpleItem):
except: except:
self.indexed_attrs = [ self.id ] self.indexed_attrs = [ self.id ]
# It was a mistake to use a __len__ attribute here, but it's not self._length = BTrees.Length.Length()
# worth changing at this point, as there is old data with this
# attribute name. :( See __len__ method docstring
self.__len__ = BTrees.Length.Length()
self.clear() self.clear()
def __len__(self): def __len__(self):
"""Return the number of objects indexed.""" return self._length()
# The instance __len__ attr isn't effective because
# Python cached this method in a slot,
__len__ = self.__dict__.get('__len__')
if __len__ is not None:
return __len__()
return len(self._unindex)
def getId(self): def getId(self):
return self.id return self.id
def clear(self): def clear(self):
# inplace opportunistic conversion from old-style to new style BTrees
try: self.__len__.set(0)
except AttributeError: self.__len__=BTrees.Length.Length()
self._index = OOBTree() self._index = OOBTree()
self._unindex = IOBTree() self._unindex = IOBTree()
...@@ -158,12 +144,12 @@ class UnIndex(SimpleItem): ...@@ -158,12 +144,12 @@ class UnIndex(SimpleItem):
indexRow.remove(documentId) indexRow.remove(documentId)
if not indexRow: if not indexRow:
del self._index[entry] del self._index[entry]
try: self.__len__.change(-1) try: self._length.change(-1)
except AttributeError: pass # pre-BTrees-module instance except AttributeError: pass # pre-BTrees-module instance
except AttributeError: except AttributeError:
# index row is an int # index row is an int
del self._index[entry] del self._index[entry]
try: self.__len__.change(-1) try: self._length.change(-1)
except AttributeError: pass # pre-BTrees-module instance except AttributeError: pass # pre-BTrees-module instance
except: except:
LOG.error('%s: unindex_object could not remove ' LOG.error('%s: unindex_object could not remove '
...@@ -190,7 +176,7 @@ class UnIndex(SimpleItem): ...@@ -190,7 +176,7 @@ class UnIndex(SimpleItem):
# an IntSet and stuff it in first. # an IntSet and stuff it in first.
if indexRow is _marker: if indexRow is _marker:
self._index[entry] = documentId self._index[entry] = documentId
try: self.__len__.change(1) try: self._length.change(1)
except AttributeError: pass # pre-BTrees-module instance except AttributeError: pass # pre-BTrees-module instance
else: else:
try: indexRow.insert(documentId) try: indexRow.insert(documentId)
......
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