Commit 60de6f12 authored by Hanno Schlichting's avatar Hanno Schlichting

Group value indexes functions into a class

parent 8b47fab8
......@@ -28,29 +28,27 @@ REPORTS = {}
PRIORITYMAP_LOCK = allocate_lock()
PRIORITYMAP = {}
VALUE_INDEXES_LOCK = allocate_lock()
VALUE_INDEXES = frozenset()
class ValueIndexes(object):
def get_value_indexes():
return VALUE_INDEXES
lock = allocate_lock()
value = frozenset()
@classmethod
def get(cls):
return cls.value
def set_value_indexes(value):
with VALUE_INDEXES_LOCK:
global VALUE_INDEXES
VALUE_INDEXES = value
@classmethod
def set(cls, value):
with cls.lock:
cls.value = value
@classmethod
def clear(cls):
cls.set(frozenset())
def clear_value_indexes():
set_value_indexes(frozenset())
from zope.testing.cleanup import addCleanUp
addCleanUp(clear_value_indexes)
del addCleanUp
def determine_value_indexes(indexes):
@classmethod
def determine(cls, indexes):
# This function determines all indexes whose values should be respected
# in the report key. The number of unique values for the index needs to be
# lower than the MAX_DISTINCT_VALUES watermark.
......@@ -59,7 +57,7 @@ def determine_value_indexes(indexes):
# of unique values, where the number of items for each value differs a
# lot. If the number of items per value is similar, the duration of a
# query is likely similar as well.
value_indexes = get_value_indexes()
value_indexes = cls.get()
if value_indexes:
# Calculating all the value indexes is quite slow, so we do this once
# for the first query. Since this is an optimization only, slightly
......@@ -76,16 +74,20 @@ def determine_value_indexes(indexes):
# greater than zero
value_indexes.add(name)
set_value_indexes(frozenset(value_indexes))
cls.set(frozenset(value_indexes))
return value_indexes
from zope.testing.cleanup import addCleanUp
addCleanUp(ValueIndexes.clear)
del addCleanUp
def make_key(catalog, query):
if not query:
return None
indexes = catalog.indexes
valueindexes = determine_value_indexes(indexes)
valueindexes = ValueIndexes.determine(indexes)
key = keys = query.keys()
values = [name for name in keys if name in valueindexes]
......
......@@ -41,8 +41,8 @@ class TestCatalogPlan(unittest.TestCase):
self.zcat.catalog_object(obj, str(i))
def tearDown(self):
from Products.ZCatalog.plan import clear_value_indexes
clear_value_indexes()
from Products.ZCatalog.plan import ValueIndexes
ValueIndexes.clear()
def test_ReportLength(self):
""" tests the report aggregation """
......
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