[Zope-Checkins] SVN: Zope/trunk/src/Products/ZCatalog/ Respect the ILimitedResultIndex interface in the query plan

Hanno Schlichting hannosch at hannosch.eu
Mon Aug 2 15:23:40 EDT 2010


Log message for revision 115385:
  Respect the ILimitedResultIndex interface in the query plan
  

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

-=-
Modified: Zope/trunk/src/Products/ZCatalog/Catalog.py
===================================================================
--- Zope/trunk/src/Products/ZCatalog/Catalog.py	2010-08-02 19:21:24 UTC (rev 115384)
+++ Zope/trunk/src/Products/ZCatalog/Catalog.py	2010-08-02 19:23:40 UTC (rev 115385)
@@ -521,7 +521,8 @@
                 continue
 
             cr.start_split(i)
-            if ILimitedResultIndex.providedBy(index):
+            limit_result = ILimitedResultIndex.providedBy(index)
+            if limit_result:
                 r = _apply_index(query, rs)
             else:
                 r = _apply_index(query)
@@ -533,15 +534,15 @@
                 # once we don't need to support the "return everything" case
                 # anymore
                 if r is not None and not r:
-                    cr.stop_split(i, None)
+                    cr.stop_split(i, result=None, limit=limit_result)
                     return LazyCat([])
 
-                cr.stop_split(i, r)
+                cr.stop_split(i, result=r, limit=limit_result)
                 w, rs = weightedIntersection(rs, r)
                 if not rs:
                     break
             else:
-                cr.stop_split(i, None)
+                cr.stop_split(i, result=None, limit=limit_result)
 
         if rs is None:
             # None of the indexes found anything to do with the query

Modified: Zope/trunk/src/Products/ZCatalog/plan.py
===================================================================
--- Zope/trunk/src/Products/ZCatalog/plan.py	2010-08-02 19:21:24 UTC (rev 115384)
+++ Zope/trunk/src/Products/ZCatalog/plan.py	2010-08-02 19:23:40 UTC (rev 115385)
@@ -27,8 +27,8 @@
 
 Duration = namedtuple('Duration', ['start', 'end'])
 IndexMeasurement = namedtuple('IndexMeasurement',
-                              ['name', 'duration', 'num'])
-Benchmark = namedtuple('Benchmark', ['num', 'duration', 'hits'])
+                              ['name', 'duration', 'num', 'limit'])
+Benchmark = namedtuple('Benchmark', ['num', 'duration', 'hits', 'limit'])
 RecentQuery = namedtuple('RecentQuery', ['duration', 'details'])
 Report = namedtuple('Report', ['hits', 'duration', 'last'])
 
@@ -237,7 +237,7 @@
             return None
 
         # sort indexes on (mean result length, mean search time)
-        ranking = [((value.num, value.duration), name)
+        ranking = [((value.limit, value.num, value.duration), name)
                    for name, value in benchmark.items()]
         ranking.sort()
         return [r[1] for r in ranking]
@@ -249,7 +249,7 @@
     def start_split(self, name, result=None):
         self.interim[name] = Duration(time.time(), None)
 
-    def stop_split(self, name, result=None):
+    def stop_split(self, name, result=None, limit=False):
         current = time.time()
         start_time, stop_time = self.interim.get(name, Duration(None, None))
         length = 0
@@ -259,7 +259,7 @@
         self.interim[name] = Duration(start_time, current)
         dt = current - start_time
         self.res.append(IndexMeasurement(
-            name=name, duration=current - start_time, num=length))
+            name=name, duration=dt, num=length, limit=limit))
 
         if name == 'sort_on':
             # sort_on isn't an index. We only do time reporting on it
@@ -268,16 +268,17 @@
         # remember index's hits, search time and calls
         benchmark = self.benchmark
         if name not in benchmark:
-            benchmark[name] = Benchmark(num=length, duration=dt, hits=1)
+            benchmark[name] = Benchmark(num=length, duration=dt,
+                                        hits=1, limit=limit)
         else:
-            num, duration, hits = benchmark[name]
+            num, duration, hits, limit = benchmark[name]
             num = int(((num * hits) + length) / float(hits + 1))
             duration = ((duration * hits) + dt) / float(hits + 1)
             # reset adaption
             if hits % REFRESH_RATE == 0:
                 hits = 0
             hits += 1
-            benchmark[name] = Benchmark(num, duration, hits)
+            benchmark[name] = Benchmark(num, duration, hits, limit)
 
     def stop(self):
         self.end_time = time.time()



More information about the Zope-Checkins mailing list