[Zope-Checkins] SVN: Zope/trunk/src/Products/ZCatalog/plan.py Simplify key handling

Hanno Schlichting hannosch at hannosch.eu
Sun Aug 1 16:42:40 EDT 2010


Log message for revision 115351:
  Simplify key handling
  

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 20:36:07 UTC (rev 115350)
+++ Zope/trunk/src/Products/ZCatalog/plan.py	2010-08-01 20:42:39 UTC (rev 115351)
@@ -77,6 +77,9 @@
 
 
 def make_key(catalog, query):
+    if not query:
+        return None
+
     indexes = catalog.indexes
     valueindexes = determine_value_indexes(indexes)
     key = keys = query.keys()
@@ -108,10 +111,10 @@
     """
 
     def __init__(self, catalog, query=None, threshold=0.1):
-        self.init()
+        self.init_timer()
         self.catalog = catalog
         self.query = query
-        self._key = None
+        self.key = make_key(catalog, query)
         self.threshold = threshold
 
         parent = aq_parent(catalog)
@@ -122,7 +125,7 @@
             path = tuple(parent.getPhysicalPath())
         self.cid = path
 
-    def init(self):
+    def init_timer(self):
         self.res = []
         self.start_time = None
         self.interim = {}
@@ -138,7 +141,7 @@
 
     def benchmark(self):
         # holds the benchmark of each index
-        return self.prioritymap().get(self.key(), None)
+        return self.prioritymap().get(self.key, None)
 
     def plan(self):
         benchmark = self.benchmark()
@@ -151,11 +154,11 @@
         return [i[1] for i in ranking]
 
     def start(self):
-        self.init()
+        self.init_timer()
         self.start_time = time.time()
         benchmark = self.benchmark()
         if benchmark is None:
-            self.prioritymap()[self.key()] = {}
+            self.prioritymap()[self.key] = {}
 
     def start_split(self, label, result=None):
         self.interim[label] = (time.time(), None)
@@ -189,7 +192,7 @@
         self.end_time = time.time()
         self.duration = self.end_time - self.start_time
 
-        key = self.key()
+        key = self.key
         benchmark = self.benchmark()
         prioritymap = self.prioritymap()
         prioritymap[key] = benchmark
@@ -213,22 +216,13 @@
     def result(self):
         return (self.duration, tuple(self.res))
 
-    def key(self):
-        if not self._key:
-            self._key = make_key(self.catalog, self.query)
-        return self._key
-
     def log(self):
         # result of stopwatch
         res = self.result()
         if res[0] < self.threshold:
             return
 
-        # The key calculation takes a bit itself, we want to avoid that for
-        # any fast queries. This does mean that slow queries get the key
-        # calculation overhead added to their runtime.
-        key = self.key()
-
+        key = self.key
         reports_lock.acquire()
         try:
             if self.cid not in reports:



More information about the Zope-Checkins mailing list