[Checkins] SVN: Products.ZCatalog/trunk/src/Products/ZCatalog/ Remove separate ValueIndexes class and keep book keeping to the priority map. This ensures we have separate value index sets per catalog

Hanno Schlichting hannosch at hannosch.eu
Thu Oct 20 09:18:11 EST 2011


Log message for revision 123120:
  Remove separate ValueIndexes class and keep book keeping to the priority map. This ensures we have separate value index sets per catalog
  

Changed:
  U   Products.ZCatalog/trunk/src/Products/ZCatalog/ZCatalog.py
  U   Products.ZCatalog/trunk/src/Products/ZCatalog/plan.py
  U   Products.ZCatalog/trunk/src/Products/ZCatalog/tests/test_plan.py

-=-
Modified: Products.ZCatalog/trunk/src/Products/ZCatalog/ZCatalog.py
===================================================================
--- Products.ZCatalog/trunk/src/Products/ZCatalog/ZCatalog.py	2011-10-20 14:02:06 UTC (rev 123119)
+++ Products.ZCatalog/trunk/src/Products/ZCatalog/ZCatalog.py	2011-10-20 14:18:10 UTC (rev 123120)
@@ -900,9 +900,13 @@
             output.append('  %s: {' % repr(cid))
             for querykey, details in sorted(plan.items()):
                 output.append('    %s: {' % repr(querykey))
-                for indexname, benchmark in sorted(details.items()):
-                    tuplebench = (round(benchmark[0], 4), ) + benchmark[1:]
-                    output.append('      %r:\n      %r,' % (indexname, tuplebench))
+                if isinstance(details, (frozenset, set)):
+                    # todo: print out value indexes
+                    pass
+                else:
+                    for indexname, benchmark in sorted(details.items()):
+                        tuplebench = (round(benchmark[0], 4), ) + benchmark[1:]
+                        output.append('      %r:\n      %r,' % (indexname, tuplebench))
                 output.append('    },')
             output.append('  },')
         output.append('}')

Modified: Products.ZCatalog/trunk/src/Products/ZCatalog/plan.py
===================================================================
--- Products.ZCatalog/trunk/src/Products/ZCatalog/plan.py	2011-10-20 14:02:06 UTC (rev 123119)
+++ Products.ZCatalog/trunk/src/Products/ZCatalog/plan.py	2011-10-20 14:18:10 UTC (rev 123120)
@@ -125,29 +125,6 @@
     value = {}
 
 
-class ValueIndexes(object):
-    """Holds a set of index names considered to have an uneven value
-    distribution.
-    """
-
-    lock = allocate_lock()
-    value = frozenset()
-
-    @classmethod
-    def get(cls):
-        return cls.value
-
-    @classmethod
-    def set(cls, value):
-        value = frozenset(value)
-        with cls.lock:
-            cls.value = value
-
-    @classmethod
-    def clear(cls):
-        cls.set(frozenset())
-
-
 class CatalogPlan(object):
     """Catalog plan class to measure and identify catalog queries and plan
     their execution.
@@ -155,11 +132,11 @@
 
     def __init__(self, catalog, query=None, threshold=0.1):
         self.catalog = catalog
+        self.cid = self.get_id()
         self.query = query
         self.key = self.make_key(query)
         self.benchmark = {}
         self.threshold = threshold
-        self.cid = self.get_id()
         self.init_timer()
 
     def get_id(self):
@@ -189,8 +166,8 @@
         # number 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 = ValueIndexes.get()
-        if value_indexes:
+        value_indexes = PriorityMap.get_entry(self.cid, VALUE_INDEX_KEY)
+        if isinstance(value_indexes, (frozenset, set)):
             # 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
@@ -206,7 +183,8 @@
                     # greater than zero
                     value_indexes.add(name)
 
-        ValueIndexes.set(value_indexes)
+        value_indexes = frozenset(value_indexes)
+        PriorityMap.set_entry(self.cid, VALUE_INDEX_KEY, value_indexes)
         return value_indexes
 
     def make_key(self, query):
@@ -336,5 +314,4 @@
 from zope.testing.cleanup import addCleanUp
 addCleanUp(PriorityMap.clear)
 addCleanUp(Reports.clear)
-addCleanUp(ValueIndexes.clear)
 del addCleanUp

Modified: Products.ZCatalog/trunk/src/Products/ZCatalog/tests/test_plan.py
===================================================================
--- Products.ZCatalog/trunk/src/Products/ZCatalog/tests/test_plan.py	2011-10-20 14:02:06 UTC (rev 123119)
+++ Products.ZCatalog/trunk/src/Products/ZCatalog/tests/test_plan.py	2011-10-20 14:18:10 UTC (rev 123120)
@@ -272,25 +272,13 @@
         self.assertEquals(plan.valueindexes(), frozenset())
 
     def test_valueindexes_set(self):
-        from ..plan import ValueIndexes
-        indexes = ('index1', 'index2')
-        ValueIndexes.set(indexes)
+        from ..plan import PriorityMap
+        from ..plan import VALUE_INDEX_KEY
         plan = self._makeOne()
+        indexes = frozenset(['index1', 'index2'])
+        PriorityMap.set_entry(plan.cid, VALUE_INDEX_KEY, indexes)
         self.assertEquals(plan.valueindexes(), frozenset(indexes))
 
-    def test_valueindexes_clear(self):
-        from ..plan import ValueIndexes
-        ValueIndexes.set(('index1', ))
-        ValueIndexes.clear()
-        plan = self._makeOne()
-        self.assertEquals(plan.valueindexes(), frozenset())
-
-    def test_valueindexes_already_set(self):
-        from ..plan import ValueIndexes
-        ValueIndexes.set(('index1', ))
-        plan = self._makeOne()
-        self.assertEquals(plan.valueindexes(), frozenset(('index1', )))
-
     # Test the actual logic for determining value indexes
     # Test make_key
 



More information about the checkins mailing list