Commit b0b04404 authored by Hanno Schlichting's avatar Hanno Schlichting

Make sure we actually do what queryplan did and support all the weird ways in...

Make sure we actually do what queryplan did and support all the weird ways in which one can pass query restrictions to the catalog
parent c9ba36fb
...@@ -27,7 +27,7 @@ value_indexes = frozenset() ...@@ -27,7 +27,7 @@ value_indexes = frozenset()
MAX_DISTINCT_VALUES = 10 MAX_DISTINCT_VALUES = 10
def determine_value_indexes(catalog): def determine_value_indexes(indexes):
# This function determines all indexes whose values should be respected # This function determines all indexes whose values should be respected
# in the report key. The number of unique values for the index 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. # lower than the MAX_DISTINCT_VALUES watermark.
...@@ -45,7 +45,7 @@ def determine_value_indexes(catalog): ...@@ -45,7 +45,7 @@ def determine_value_indexes(catalog):
return value_indexes return value_indexes
new_value_indexes = set() new_value_indexes = set()
for name, index in catalog.indexes.items(): for name, index in indexes.items():
if IUniqueValueIndex.providedBy(index): if IUniqueValueIndex.providedBy(index):
values = index.uniqueValues() values = index.uniqueValues()
if values and len(values) < MAX_DISTINCT_VALUES: if values and len(values) < MAX_DISTINCT_VALUES:
...@@ -75,17 +75,38 @@ addCleanUp(clear_value_indexes) ...@@ -75,17 +75,38 @@ addCleanUp(clear_value_indexes)
del addCleanUp del addCleanUp
def make_key(catalog, request): def make_query(indexes, request):
valueindexes = determine_value_indexes(catalog) # This is a bit of a mess, but the ZCatalog API supports passing
# in query restrictions in almost arbitary ways
if isinstance(request, dict): if isinstance(request, dict):
keydict = request.copy() query = request.copy()
else: else:
keydict = {} query = {}
keydict.update(request.keywords) query.update(request.keywords)
if isinstance(request.request, dict): real_req = request.request
keydict.update(request.request) if isinstance(real_req, dict):
key = keys = keydict.keys() query.update(real_req)
known_keys = query.keys()
# The request has too many places where an index restriction might be
# specified. Putting all of request.form, request.other, ... into the
# key isn't what we want either, so we iterate over all known indexes
# instead and see if they are in the request.
for iid in indexes.keys():
if iid in known_keys:
continue
value = real_req.get(iid)
if value:
query[iid] = value
return query
def make_key(catalog, request):
indexes = catalog.indexes
valueindexes = determine_value_indexes(indexes)
query = make_query(indexes, request)
key = keys = query.keys()
values = [name for name in keys if name in valueindexes] values = [name for name in keys if name in valueindexes]
if values: if values:
...@@ -95,7 +116,7 @@ def make_key(catalog, request): ...@@ -95,7 +116,7 @@ def make_key(catalog, request):
key = [name for name in keys if name not in values] key = [name for name in keys if name not in values]
for name in values: for name in values:
v = keydict.get(name, []) v = query.get(name, [])
if isinstance(v, (tuple, list)): if isinstance(v, (tuple, list)):
v = list(v) v = list(v)
v.sort() v.sort()
......
...@@ -899,7 +899,7 @@ class TestCatalogReport(unittest.TestCase): ...@@ -899,7 +899,7 @@ class TestCatalogReport(unittest.TestCase):
self.assertEqual(4, len(self.zcat.getCatalogReport())) self.assertEqual(4, len(self.zcat.getCatalogReport()))
def test_ReportCounter(self): def test_ReportCounter(self):
""" tests the counter of equal queries """ """ tests the counter of equal queries """
self.zcat.manage_resetCatalogReport() self.zcat.manage_resetCatalogReport()
...@@ -913,7 +913,7 @@ class TestCatalogReport(unittest.TestCase): ...@@ -913,7 +913,7 @@ class TestCatalogReport(unittest.TestCase):
self.assertEqual(r['counter'],3) self.assertEqual(r['counter'],3)
def test_ReportKey(self): def test_ReportKey(self):
""" tests the query keys for uniqueness """ """ tests the query keys for uniqueness """
# query key 1 # query key 1
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment