[Zope-Checkins] SVN: Zope/branches/andig-catalog-report/src/Products/ZCatalog/ Change the determine_value_indexes function to actually do what it promises
Hanno Schlichting
hannosch at hannosch.eu
Sat Jul 24 11:40:08 EDT 2010
Log message for revision 115018:
Change the determine_value_indexes function to actually do what it promises
Changed:
U Zope/branches/andig-catalog-report/src/Products/ZCatalog/CatalogReport.py
U Zope/branches/andig-catalog-report/src/Products/ZCatalog/tests/testCatalog.py
-=-
Modified: Zope/branches/andig-catalog-report/src/Products/ZCatalog/CatalogReport.py
===================================================================
--- Zope/branches/andig-catalog-report/src/Products/ZCatalog/CatalogReport.py 2010-07-24 15:23:19 UTC (rev 115017)
+++ Zope/branches/andig-catalog-report/src/Products/ZCatalog/CatalogReport.py 2010-07-24 15:40:08 UTC (rev 115018)
@@ -20,25 +20,26 @@
writelock = allocate_lock()
reports = {}
-MAX_DISTINCT_VALUES = 20
+MAX_DISTINCT_VALUES = 10
LOG = logging.getLogger('CatalogReport')
def determine_value_indexes(catalog):
# This function determines all indexes whose values should be respected
- # in the prioritymap key. A index type needs to be registered in the
- # VALUETYPES module global and the number of unique values needs to be
+ # in the report key. The number of unique values for the index needs to be
# lower than the MAX_DISTINCT_VALUES watermark.
valueindexes = []
for name, index in catalog.indexes.items():
if IUniqueValueIndex.providedBy(index):
- if len(index) < MAX_DISTINCT_VALUES:
- # Checking for len of an index should be fast. It's a stored
- # BTrees.Length value and requires no calculation.
+ values = index.uniqueValues()
+ if values and len(values) < MAX_DISTINCT_VALUES:
+ # Only consider indexes which actually return a number
+ # greater than zero
valueindexes.append(name)
return frozenset(valueindexes)
+
def make_key(catalog,request):
valueindexes = determine_value_indexes(catalog)
Modified: Zope/branches/andig-catalog-report/src/Products/ZCatalog/tests/testCatalog.py
===================================================================
--- Zope/branches/andig-catalog-report/src/Products/ZCatalog/tests/testCatalog.py 2010-07-24 15:23:19 UTC (rev 115017)
+++ Zope/branches/andig-catalog-report/src/Products/ZCatalog/tests/testCatalog.py 2010-07-24 15:40:08 UTC (rev 115018)
@@ -870,11 +870,10 @@
self.zcat.addIndex('title', 'TextIndex')
self.zcat._catalog.vocabulary = vocabulary
- for i in range(10):
+ for i in range(9):
obj = zdummy(i)
obj.big = i > 5
self.zcat.catalog_object(obj, str(i))
-
def test_ReportLength(self):
""" tests the report aggregation """
@@ -912,7 +911,7 @@
def test_ReportKey(self):
""" tests the query keys for uniqueness """
-
+
# query key 1
key = ('sort_on', ('big', 'True'))
self.zcat.manage_resetCatalogReport()
@@ -933,22 +932,19 @@
self.assertEqual(r['query'],key)
self.assertEqual(r['counter'],1)
-
+
# query key 3
key = ('sort_on', ('num', '[3, 4, 5]'))
self.zcat.manage_resetCatalogReport()
-
- self.zcat.searchResults(num=[5,4,3],sort_on='num')
- self.zcat.searchResults(num=(3,4,5),sort_on='num')
+
+ self.zcat.searchResults(num=[5,4,3], sort_on='num')
+ self.zcat.searchResults(num=(3,4,5), sort_on='num')
r = self.zcat.getCatalogReport()[0]
- #print 'hits: %(counter)s, mean duration: %(duration)3.2fms, key: %(query)s' % r
-
- self.assertEqual(r['query'],key)
- self.assertEqual(r['counter'],2)
-
-
+ self.assertEqual(r['query'], key)
+ self.assertEqual(r['counter'], 2)
+
def test_suite():
suite = unittest.TestSuite()
suite.addTest( unittest.makeSuite( TestAddDelColumn ) )
More information about the Zope-Checkins
mailing list