[Checkins] SVN: Products.ZCatalog/trunk/ Added automatic sorting limit calculation based on batch arguments. If the query contains a `b_start` and `b_size` argument and no explicit `sort_limit` is provided, the sort limit will be calculated as `b_start + b_size`.

Hanno Schlichting hannosch at hannosch.eu
Sat Dec 25 14:39:16 EST 2010


Log message for revision 119106:
  Added automatic sorting limit calculation based on batch arguments. If the query contains a `b_start` and `b_size` argument and no explicit `sort_limit` is provided, the sort limit will be calculated as `b_start + b_size`.
  

Changed:
  U   Products.ZCatalog/trunk/CHANGES.txt
  U   Products.ZCatalog/trunk/src/Products/ZCatalog/Catalog.py
  U   Products.ZCatalog/trunk/src/Products/ZCatalog/tests/test_catalog.py

-=-
Modified: Products.ZCatalog/trunk/CHANGES.txt
===================================================================
--- Products.ZCatalog/trunk/CHANGES.txt	2010-12-25 19:19:17 UTC (rev 119105)
+++ Products.ZCatalog/trunk/CHANGES.txt	2010-12-25 19:39:16 UTC (rev 119106)
@@ -4,8 +4,12 @@
 2.13.1 (unreleased)
 -------------------
 
-- Avoid pre-allocation of marker items in `LazyMap.
+- Added automatic sorting limit calculation based on batch arguments. If the
+  query contains a `b_start` and `b_size` argument and no explicit `sort_limit`
+  is provided, the sort limit will be calculated as `b_start + b_size`.
 
+- Avoid pre-allocation of marker items in `LazyMap`.
+
 2.13.0 (2010-12-25)
 -------------------
 

Modified: Products.ZCatalog/trunk/src/Products/ZCatalog/Catalog.py
===================================================================
--- Products.ZCatalog/trunk/src/Products/ZCatalog/Catalog.py	2010-12-25 19:19:17 UTC (rev 119105)
+++ Products.ZCatalog/trunk/src/Products/ZCatalog/Catalog.py	2010-12-25 19:39:16 UTC (rev 119106)
@@ -546,6 +546,11 @@
             else:
                 cr.stop_split(i, result=None, limit=limit_result)
 
+        # Try to deduce the sort limit from batching arguments
+        if limit is None:
+            if 'b_start' in query and 'b_size' in query:
+                limit = int(query['b_start']) + int(query['b_size'])
+
         if rs is None:
             # None of the indexes found anything to do with the query
             # We take this to mean that the query was empty (an empty filter)

Modified: Products.ZCatalog/trunk/src/Products/ZCatalog/tests/test_catalog.py
===================================================================
--- Products.ZCatalog/trunk/src/Products/ZCatalog/tests/test_catalog.py	2010-12-25 19:19:17 UTC (rev 119105)
+++ Products.ZCatalog/trunk/src/Products/ZCatalog/tests/test_catalog.py	2010-12-25 19:39:16 UTC (rev 119106)
@@ -348,6 +348,24 @@
         self.assertEqual(a.actual_result_count, self.upper)
         self.assertEqual(a[0].num, self.upper - 1)
 
+    def testSortLimitViaBatchingArgsStart(self):
+        query = dict(att1='att1', sort_on='num', b_start=0, b_size=5)
+        result = self._catalog(query)
+        self.assertEqual(result.actual_result_count, 100)
+        self.assertEqual([r.num for r in result], range(5))
+
+    def testSortLimitViaBatchingArgsMiddle(self):
+        query = dict(att1='att1', sort_on='num', b_start=11, b_size=17)
+        result = self._catalog(query)
+        self.assertEqual(result.actual_result_count, 100)
+        self.assertEqual([r.num for r in result], range(28))
+
+    def testSortLimitViaBatchingArgsEnd(self):
+        query = dict(att1='att1', sort_on='num', b_start=90, b_size=15)
+        result = self._catalog(query)
+        self.assertEqual(result.actual_result_count, 100)
+        self.assertEqual([r.num for r in result], range(100))
+
     # _get_sort_attr
     # _getSortIndex
     # searchResults



More information about the checkins mailing list