[Zope-Checkins] SVN: Zope/trunk/src/Products/ZCatalog/plan.py Get us a get/set for value indexes

Hanno Schlichting hannosch at hannosch.eu
Sun Aug 1 18:07:44 EDT 2010


Log message for revision 115358:
  Get us a get/set for value indexes
  

Changed:
  U   Zope/trunk/src/Products/ZCatalog/plan.py

-=-
Modified: Zope/trunk/src/Products/ZCatalog/plan.py
===================================================================
--- Zope/trunk/src/Products/ZCatalog/plan.py	2010-08-01 21:56:53 UTC (rev 115357)
+++ Zope/trunk/src/Products/ZCatalog/plan.py	2010-08-01 22:07:43 UTC (rev 115358)
@@ -19,6 +19,9 @@
 from Acquisition import aq_parent
 from Products.PluginIndexes.interfaces import IUniqueValueIndex
 
+MAX_DISTINCT_VALUES = 10
+REFRESH_RATE = 100
+
 REPORTS_LOCK = allocate_lock()
 REPORTS = {}
 
@@ -28,10 +31,25 @@
 VALUE_INDEXES_LOCK = allocate_lock()
 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):
     # 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
@@ -41,40 +59,27 @@
     # 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.
-    global VALUE_INDEXES
-    if VALUE_INDEXES:
+    value_indexes = get_value_indexes()
+    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
         # outdated results based on index changes in the running process
         # can be ignored.
-        return VALUE_INDEXES
+        return value_indexes
 
-    new_value_indexes = set()
+    value_indexes = set()
     for name, index in indexes.items():
         if IUniqueValueIndex.providedBy(index):
             values = index.uniqueValues()
             if values and len(list(values)) < MAX_DISTINCT_VALUES:
                 # Only consider indexes which actually return a number
                 # greater than zero
-                new_value_indexes.add(name)
+                value_indexes.add(name)
 
-    with VALUE_INDEXES_LOCK:
-        VALUE_INDEXES = frozenset(new_value_indexes)
+    set_value_indexes(frozenset(value_indexes))
+    return value_indexes
 
-    return VALUE_INDEXES
 
-
-def clear_value_indexes():
-    global 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):
     if not query:
         return None



More information about the Zope-Checkins mailing list