[Checkins] SVN: Products.ZCatalog/trunk/ Preserve `actual_result_count` on flattening nested LazyCat's.
Hanno Schlichting
hannosch at hannosch.eu
Mon Dec 27 06:38:23 EST 2010
Log message for revision 119161:
Preserve `actual_result_count` on flattening nested LazyCat's.
Changed:
U Products.ZCatalog/trunk/CHANGES.txt
U Products.ZCatalog/trunk/src/Products/ZCatalog/Lazy.py
U Products.ZCatalog/trunk/src/Products/ZCatalog/tests/test_lazy.py
-=-
Modified: Products.ZCatalog/trunk/CHANGES.txt
===================================================================
--- Products.ZCatalog/trunk/CHANGES.txt 2010-12-27 11:18:08 UTC (rev 119160)
+++ Products.ZCatalog/trunk/CHANGES.txt 2010-12-27 11:38:23 UTC (rev 119161)
@@ -4,6 +4,8 @@
2.13.2 (unreleased)
-------------------
+- Preserve `actual_result_count` on flattening nested LazyCat's.
+
- Preserve the `actual_result_count` on all lazy return values. This allows
to get proper batching information from catalog results which have been
restricted by `sort_limit`.
Modified: Products.ZCatalog/trunk/src/Products/ZCatalog/Lazy.py
===================================================================
--- Products.ZCatalog/trunk/src/Products/ZCatalog/Lazy.py 2010-12-27 11:18:08 UTC (rev 119160)
+++ Products.ZCatalog/trunk/src/Products/ZCatalog/Lazy.py 2010-12-27 11:38:23 UTC (rev 119161)
@@ -74,6 +74,7 @@
"""
def __init__(self, sequences, length=None, actual_result_count=None):
+ flattened_count = 0
if len(sequences) < 100:
# Optimize structure of LazyCats to avoid nesting
# We don't do this for large numbers of input sequences
@@ -84,8 +85,13 @@
# If one of the sequences passed is itself a LazyCat, add
# its base sequences rather than nest LazyCats
flattened_seq.extend(s._seq)
+ flattened_count += s.actual_result_count
+ elif isinstance(s, Lazy):
+ flattened_seq.append(s)
+ flattened_count += s.actual_result_count
else:
flattened_seq.append(s)
+ flattened_count += len(s)
sequences = flattened_seq
self._seq = sequences
self._data = []
@@ -95,6 +101,8 @@
self._len = length
if actual_result_count is not None:
self.actual_result_count = actual_result_count
+ else:
+ self.actual_result_count = flattened_count
def __getitem__(self, index):
data = self._data
Modified: Products.ZCatalog/trunk/src/Products/ZCatalog/tests/test_lazy.py
===================================================================
--- Products.ZCatalog/trunk/src/Products/ZCatalog/tests/test_lazy.py 2010-12-27 11:18:08 UTC (rev 119160)
+++ Products.ZCatalog/trunk/src/Products/ZCatalog/tests/test_lazy.py 2010-12-27 11:38:23 UTC (rev 119161)
@@ -38,6 +38,10 @@
from Products.ZCatalog.Lazy import LazyCat
return LazyCat(sequences)
+ def _createLValues(self, seq):
+ from Products.ZCatalog.Lazy import LazyValues
+ return LazyValues(seq)
+
def test_empty(self):
lcat = self._createLSeq([])
self._compare(lcat, [])
@@ -106,7 +110,26 @@
self.assertEqual(len(lcat), 10)
self.assertEqual(lcat.actual_result_count, 10)
+ def test_actual_result_count(self):
+ # specify up-front
+ lcat = self._createLSeq(range(10))
+ lcat.actual_result_count = 100
+ self.assertEqual(len(lcat), 10)
+ self.assertEqual(lcat.actual_result_count, 100)
+
+ lvalues = self._createLValues([])
+ self.assertEqual(len(lvalues), 0)
+ self.assertEqual(lvalues.actual_result_count, 0)
+
+ combined = lvalues + lcat
+ self.assertEqual(len(combined), 10)
+ self.assertEqual(combined.actual_result_count, 100)
+
+ combined.actual_result_count = 5
+ self.assertEqual(combined.actual_result_count, 5)
+
+
class TestLazyMap(TestLazyCat):
def _createLSeq(self, *seq):
More information about the checkins
mailing list