[Checkins] SVN: Products.ZCatalog/trunk/src/Products/ZCatalog/ Move `make_key` onto the plan instead
Hanno Schlichting
hannosch at hannosch.eu
Thu Oct 20 08:42:56 EST 2011
Log message for revision 123116:
Move `make_key` onto the plan instead
Changed:
U Products.ZCatalog/trunk/src/Products/ZCatalog/Catalog.py
U Products.ZCatalog/trunk/src/Products/ZCatalog/plan.py
-=-
Modified: Products.ZCatalog/trunk/src/Products/ZCatalog/Catalog.py
===================================================================
--- Products.ZCatalog/trunk/src/Products/ZCatalog/Catalog.py 2011-10-20 13:34:43 UTC (rev 123115)
+++ Products.ZCatalog/trunk/src/Products/ZCatalog/Catalog.py 2011-10-20 13:42:55 UTC (rev 123116)
@@ -33,7 +33,6 @@
from Lazy import LazyMap, LazyCat, LazyValues
from CatalogBrains import AbstractCatalogBrain, NoBrainer
from .plan import CatalogPlan
-from .plan import ValueIndexes
LOG = logging.getLogger('Zope.ZCatalog')
@@ -419,34 +418,6 @@
# This is the Catalog search engine. Most of the heavy lifting happens
# below
- def make_key(self, query):
- if not query:
- return None
-
- indexes = self.indexes
- valueindexes = ValueIndexes.determine(indexes)
- key = keys = query.keys()
-
- values = [name for name in keys if name in valueindexes]
- if values:
- # If we have indexes whose values should be considered, we first
- # preserve all normal indexes and then add the keys whose values
- # matter including their value into the key
- key = [name for name in keys if name not in values]
- for name in values:
-
- v = query.get(name, [])
- if isinstance(v, (tuple, list)):
- v = list(v)
- v.sort()
-
- # We need to make sure the key is immutable, repr() is an easy way
- # to do this without imposing restrictions on the types of values
- key.append((name, repr(v)))
-
- key = tuple(sorted(key))
- return key
-
def make_query(self, request):
# This is a bit of a mess, but the ZCatalog API has traditionally
# supported passing in query restrictions in almost arbitary ways
@@ -603,7 +574,7 @@
warnings.warn('Your query %s produced no query restriction. '
'Currently the entire catalog content is returned. '
'In Zope 2.14 this will result in an empty LazyCat '
- 'to be returned.' % repr(self.make_key(query)),
+ 'to be returned.' % repr(cr.make_key(query)),
DeprecationWarning, stacklevel=3)
rlen = len(self)
Modified: Products.ZCatalog/trunk/src/Products/ZCatalog/plan.py
===================================================================
--- Products.ZCatalog/trunk/src/Products/ZCatalog/plan.py 2011-10-20 13:34:43 UTC (rev 123115)
+++ Products.ZCatalog/trunk/src/Products/ZCatalog/plan.py 2011-10-20 13:42:55 UTC (rev 123116)
@@ -185,7 +185,7 @@
def __init__(self, catalog, query=None, threshold=0.1):
self.catalog = catalog
self.query = query
- self.key = catalog.make_key(query)
+ self.key = self.make_key(query)
self.benchmark = {}
self.threshold = threshold
self.cid = self.get_id()
@@ -207,6 +207,34 @@
self.stop_time = None
self.duration = None
+ def make_key(self, query):
+ if not query:
+ return None
+
+ indexes = self.catalog.indexes
+ valueindexes = ValueIndexes.determine(indexes)
+ key = keys = query.keys()
+
+ values = [name for name in keys if name in valueindexes]
+ if values:
+ # If we have indexes whose values should be considered, we first
+ # preserve all normal indexes and then add the keys whose values
+ # matter including their value into the key
+ key = [name for name in keys if name not in values]
+ for name in values:
+
+ v = query.get(name, [])
+ if isinstance(v, (tuple, list)):
+ v = list(v)
+ v.sort()
+
+ # We need to make sure the key is immutable, repr() is an easy way
+ # to do this without imposing restrictions on the types of values
+ key.append((name, repr(v)))
+
+ key = tuple(sorted(key))
+
+ return key
def plan(self):
benchmark = PriorityMap.get_entry(self.cid, self.key)
if not benchmark:
More information about the checkins
mailing list