Skip to content

Commit

Permalink
Remove BBB code.
Browse files Browse the repository at this point in the history
  • Loading branch information
hannosch committed Aug 26, 2016
1 parent 426d5e9 commit 0a593ca
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 56 deletions.
1 change: 1 addition & 0 deletions setup.py
Expand Up @@ -55,6 +55,7 @@
'zExceptions',
'ZODB',
'Zope2 >= 4.0.dev0',
'zope.deferredimport',
'zope.dottedname',
'zope.globalrequest',
'zope.interface',
Expand Down
30 changes: 4 additions & 26 deletions src/Products/PluginIndexes/BooleanIndex/BooleanIndex.py
Expand Up @@ -91,25 +91,11 @@ def _invert_index(self, documentId=None):
length -= 1
self._index_length = BTrees.Length.Length(length)

def _inline_migration(self):
self._length = BTrees.Length.Length(len(self._unindex.keys()))
self._index_length = BTrees.Length.Length(len(self._index))
if self._index_length.value > (self._length.value / 2):
self._index_value = 1
self._invert_index()
else:
# set an instance variable
self._index_value = 1

def insertForwardIndexEntry(self, entry, documentId):
"""If the value matches the indexed one, insert into treeset
"""
# when we get the first entry, decide to index the opposite of what
# we got, as indexing zero items is fewer than one
# BBB inline migration
if self._index_length is None:
self._inline_migration()

# When we get the first entry, decide to index the opposite of what
# we got, as indexing zero items is fewer than one.
if self._length.value == 0:
self._index_value = int(not bool(entry))

Expand All @@ -132,16 +118,10 @@ def removeForwardIndexEntry(self, entry, documentId, check=True):
"""Take the entry provided and remove any reference to documentId
in its entry in the index.
"""
index_length = self._index_length
if index_length is None:
self._inline_migration()

if bool(entry) is bool(self._index_value):
try:
self._index.remove(documentId)
# BBB inline migration
length = self._index_length
length.change(-1)
self._index_length.change(-1)
except ConflictError:
raise
except Exception:
Expand All @@ -152,11 +132,9 @@ def removeForwardIndexEntry(self, entry, documentId, check=True):
str(documentId),
str(self.id)))
elif check:
length = self._length.value
index_length = self._index_length.value
# is the index (after removing the current entry) larger than
# 60% of the total length? than switch the indexed value
if (index_length) <= ((length - 1) * 0.6):
if (self._index_length.value) <= ((self._length.value - 1) * 0.6):
self._invert_index(documentId)
return

Expand Down
20 changes: 0 additions & 20 deletions src/Products/PluginIndexes/BooleanIndex/tests.py
Expand Up @@ -199,26 +199,6 @@ def test_histogram(self):
self.assertEqual(hist[True], 5)
self.assertEqual(hist[False], 15)

def test_migration(self):
index = self._makeOne()
for i in range(0, 100):
obj = Dummy(i, i < 80 and True or False)
index._index_object(obj.id, obj, attr='truth')
# now hack the state to match what we had before
delattr(index, '_index_length')
delattr(index, '_index_value')
# we had True values in _index even though there was more of them
index._index.clear()
index._index.update(range(0, 80))
# the length only kept track of the _index
index._length.change(-20)
# remove one to trigger migration
index.unindex_object(99)
self.assertEqual(index._length.value, 99)
self.assertEqual(index._index_value, 0)
self.assertEqual(index._index_length.value, 19)
self.assertEqual(list(index._index), range(80, 99))

def test_reindexation_when_index_reversed(self):
index = self._makeOne()
obj1 = Dummy(1, False)
Expand Down
3 changes: 1 addition & 2 deletions src/Products/PluginIndexes/common/UnIndex.py
Expand Up @@ -652,8 +652,7 @@ def hasUniqueValuesFor(self, name):
return 0

def getIndexSourceNames(self):
""" return sequence of indexed attributes """
# BBB: older indexes didn't have 'indexed_attrs'
"""Return sequence of indexed attributes."""
return getattr(self, 'indexed_attrs', [self.id])

def getIndexQueryNames(self):
Expand Down
2 changes: 1 addition & 1 deletion src/Products/ZCatalog/Catalog.py
Expand Up @@ -29,10 +29,10 @@
import ExtensionClass
from Missing import MV
from Persistence import Persistent
from ZTUtils.Lazy import LazyMap, LazyCat, LazyValues

from Products.PluginIndexes.interfaces import ILimitedResultIndex
from Products.PluginIndexes.interfaces import ITransposeQuery
from .Lazy import LazyMap, LazyCat, LazyValues
from .CatalogBrains import AbstractCatalogBrain, NoBrainer
from .plan import CatalogPlan
from .ProgressHandler import ZLogHandler
Expand Down
18 changes: 11 additions & 7 deletions src/Products/ZCatalog/Lazy.py
Expand Up @@ -11,11 +11,15 @@
#
##############################################################################

from ZTUtils.Lazy import ( # NOQA
Lazy,
LazyCat,
LazyFilter,
LazyMap,
LazyMop,
LazyValues,
from zope.deferredimport import deprecated

# BBB ZCatalog 5.0
deprecated(
'Please import from ZTUtils.Lazy.',
Lazy='ZTUtils.Lazy:Lazy',
LazyCat='ZTUtils.Lazy:LazyCat',
LazyFilter='ZTUtils.Lazy:LazyFilter',
LazyMap='ZTUtils.Lazy:LazyMap',
LazyMop='ZTUtils.Lazy:LazyMop',
LazyValues='ZTUtils.Lazy:LazyValues',
)

0 comments on commit 0a593ca

Please sign in to comment.