Commit 8b47fab8 authored by Hanno Schlichting's avatar Hanno Schlichting

Get us a get/set for value indexes

parent b8f178d3
...@@ -19,6 +19,9 @@ from Acquisition import aq_base ...@@ -19,6 +19,9 @@ from Acquisition import aq_base
from Acquisition import aq_parent from Acquisition import aq_parent
from Products.PluginIndexes.interfaces import IUniqueValueIndex from Products.PluginIndexes.interfaces import IUniqueValueIndex
MAX_DISTINCT_VALUES = 10
REFRESH_RATE = 100
REPORTS_LOCK = allocate_lock() REPORTS_LOCK = allocate_lock()
REPORTS = {} REPORTS = {}
...@@ -28,8 +31,23 @@ PRIORITYMAP = {} ...@@ -28,8 +31,23 @@ PRIORITYMAP = {}
VALUE_INDEXES_LOCK = allocate_lock() VALUE_INDEXES_LOCK = allocate_lock()
VALUE_INDEXES = frozenset() VALUE_INDEXES = frozenset()
MAX_DISTINCT_VALUES = 10
REFRESH_RATE = 100 def get_value_indexes():
return VALUE_INDEXES
def set_value_indexes(value):
with VALUE_INDEXES_LOCK:
global VALUE_INDEXES
VALUE_INDEXES = value
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): def determine_value_indexes(indexes):
...@@ -41,38 +59,25 @@ def determine_value_indexes(indexes): ...@@ -41,38 +59,25 @@ def determine_value_indexes(indexes):
# of unique values, where the number of items for each value differs a # 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 # lot. If the number of items per value is similar, the duration of a
# query is likely similar as well. # query is likely similar as well.
global VALUE_INDEXES value_indexes = get_value_indexes()
if VALUE_INDEXES: if value_indexes:
# Calculating all the value indexes is quite slow, so we do this once # Calculating all the value indexes is quite slow, so we do this once
# for the first query. Since this is an optimization only, slightly # for the first query. Since this is an optimization only, slightly
# outdated results based on index changes in the running process # outdated results based on index changes in the running process
# can be ignored. # can be ignored.
return VALUE_INDEXES return value_indexes
new_value_indexes = set() value_indexes = set()
for name, index in indexes.items(): for name, index in indexes.items():
if IUniqueValueIndex.providedBy(index): if IUniqueValueIndex.providedBy(index):
values = index.uniqueValues() values = index.uniqueValues()
if values and len(list(values)) < MAX_DISTINCT_VALUES: if values and len(list(values)) < MAX_DISTINCT_VALUES:
# Only consider indexes which actually return a number # Only consider indexes which actually return a number
# greater than zero # greater than zero
new_value_indexes.add(name) value_indexes.add(name)
with VALUE_INDEXES_LOCK:
VALUE_INDEXES = frozenset(new_value_indexes)
return VALUE_INDEXES
def clear_value_indexes(): set_value_indexes(frozenset(value_indexes))
global VALUE_INDEXES return value_indexes
with VALUE_INDEXES_LOCK:
VALUE_INDEXES = frozenset()
from zope.testing.cleanup import addCleanUp
addCleanUp(clear_value_indexes)
del addCleanUp
def make_key(catalog, query): def make_key(catalog, query):
......
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