[Zope-Checkins] SVN: Zope/trunk/src/Products/ZCatalog/ Actually nest the queryplan on the catalog id as well
Hanno Schlichting
hannosch at hannosch.eu
Mon Aug 2 16:32:56 EDT 2010
Log message for revision 115388:
Actually nest the queryplan on the catalog id as well
Changed:
U Zope/trunk/src/Products/ZCatalog/ZCatalog.py
U Zope/trunk/src/Products/ZCatalog/plan.py
-=-
Modified: Zope/trunk/src/Products/ZCatalog/ZCatalog.py
===================================================================
--- Zope/trunk/src/Products/ZCatalog/ZCatalog.py 2010-08-02 20:17:07 UTC (rev 115387)
+++ Zope/trunk/src/Products/ZCatalog/ZCatalog.py 2010-08-02 20:32:55 UTC (rev 115388)
@@ -883,15 +883,18 @@
security.declareProtected(manage_zcatalog_entries, 'getCatalogPlan')
def getCatalogPlan(self):
"""Get a string representation of a query plan"""
- plan = PriorityMap.get_plan()
+ pmap = PriorityMap.get_value()
output = []
output.append('# query plan dumped at %r\n' % time.asctime())
output.append('queryplan = {')
- for querykey, details in sorted(plan.items()):
- output.append(' %s: {' % repr(querykey))
- for indexname, benchmark in sorted(details.items()):
- tuplebench = repr(tuple(benchmark))
- output.append(' %r:\n %s,' % (indexname, tuplebench))
+ for cid, plan in sorted(pmap.items()):
+ output.append(' %s: {' % repr(cid))
+ for querykey, details in sorted(plan.items()):
+ output.append(' %s: {' % repr(querykey))
+ for indexname, benchmark in sorted(details.items()):
+ tuplebench = repr(tuple(benchmark))
+ output.append(' %r:\n %s,' % (indexname, tuplebench))
+ output.append(' },')
output.append(' },')
output.append('}')
return '\n'.join(output)
Modified: Zope/trunk/src/Products/ZCatalog/plan.py
===================================================================
--- Zope/trunk/src/Products/ZCatalog/plan.py 2010-08-02 20:17:07 UTC (rev 115387)
+++ Zope/trunk/src/Products/ZCatalog/plan.py 2010-08-02 20:32:55 UTC (rev 115388)
@@ -35,62 +35,11 @@
logger = getLogger('Products.ZCatalog')
-class PriorityMap(object):
- """This holds a query key to Benchmark mapping."""
+class NestedDict(object):
+ """Holds a structure of two nested dicts."""
- lock = allocate_lock()
- value = {}
-
@classmethod
- def get_plan(cls):
- return cls.value.copy()
-
- @classmethod
def get(cls, key):
- return cls.value.get(key, None)
-
- @classmethod
- def set(cls, key, value):
- with cls.lock:
- cls.value[key] = value
-
- @classmethod
- def clear(cls):
- with cls.lock:
- cls.value = {}
-
- @classmethod
- def load_default(cls):
- location = environ.get('ZCATALOGQUERYPLAN')
- if location:
- try:
- pmap = resolve(location)
- logger.info('loaded priority %d map(s) from %s',
- len(pmap), location)
- # Convert simple benchmark tuples to namedtuples
- new_plan = {}
- for querykey, details in pmap.items():
- new_plan[querykey] = {}
- for indexname, benchmark in details.items():
- new_plan[querykey][indexname] = Benchmark(*benchmark)
- with cls.lock:
- cls.value = new_plan
- except ImportError:
- logger.warning('could not load priority map from %s', location)
-
-
-class Reports(object):
- """This holds a structure of nested dicts.
-
- The outer dict is a mapping of catalog id to reports. The inner dict holds
- a query key to Report mapping.
- """
-
- lock = allocate_lock()
- value = {}
-
- @classmethod
- def get(cls, key):
outer = cls.value.get(key, None)
if outer is None:
cls.set(key, {})
@@ -127,6 +76,54 @@
cls.set(key, {})
+class PriorityMap(NestedDict):
+ """This holds a structure of nested dicts.
+
+ The outer dict is a mapping of catalog id to plans. The inner dict holds
+ a query key to Benchmark mapping.
+ """
+
+ lock = allocate_lock()
+ value = {}
+
+ @classmethod
+ def get_value(cls):
+ return cls.value.copy()
+
+ @classmethod
+ def load_default(cls):
+ location = environ.get('ZCATALOGQUERYPLAN')
+ if location:
+ try:
+ pmap = resolve(location)
+ logger.info('loaded priority %d map(s) from %s',
+ len(pmap), location)
+ # Convert the simple benchmark tuples to namedtuples
+ new_plan = {}
+ for cid, plan in pmap.items():
+ new_plan[cid] = {}
+ for querykey, details in plan.items():
+ new_plan[cid][querykey] = {}
+ for indexname, benchmark in details.items():
+ new_plan[cid][querykey][indexname] = \
+ Benchmark(*benchmark)
+ with cls.lock:
+ cls.value = new_plan
+ except ImportError:
+ logger.warning('could not load priority map from %s', location)
+
+
+class Reports(NestedDict):
+ """This holds a structure of nested dicts.
+
+ The outer dict is a mapping of catalog id to reports. The inner dict holds
+ a query key to Report mapping.
+ """
+
+ lock = allocate_lock()
+ value = {}
+
+
class ValueIndexes(object):
"""Holds a set of index names considered to have an uneven value
distribution.
@@ -239,7 +236,7 @@
self.duration = None
def plan(self):
- benchmark = PriorityMap.get(self.key)
+ benchmark = PriorityMap.get_entry(self.cid, self.key)
if not benchmark:
return None
@@ -290,7 +287,7 @@
def stop(self):
self.end_time = time.time()
self.duration = self.end_time - self.start_time
- PriorityMap.set(self.key, self.benchmark)
+ PriorityMap.set_entry(self.cid, self.key, self.benchmark)
self.log()
def log(self):
More information about the Zope-Checkins
mailing list