Commit aa7d9cb8 authored by Hanno Schlichting's avatar Hanno Schlichting

Rename the catalog report to plan to fit its new purpose

parent 16671146
......@@ -31,8 +31,8 @@ from BTrees.OIBTree import OIBTree
from BTrees.IOBTree import IOBTree
from Lazy import LazyMap, LazyCat, LazyValues
from CatalogBrains import AbstractCatalogBrain, NoBrainer
from .report import CatalogReport
from .report import make_key
from .plan import CatalogPlan
from .plan import make_key
LOG = logging.getLogger('Zope.ZCatalog')
......@@ -507,7 +507,7 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
# Canonicalize the request into a sensible query before passing it on
query = self.make_query(query)
cr = self.getCatalogReport(query)
cr = self.getCatalogPlan(query)
cr.start()
plan = cr.plan()
......@@ -819,12 +819,12 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
__call__ = searchResults
def getCatalogReport(self, query=None):
"""Reports about the duration of queries.
def getCatalogPlan(self, query=None):
"""Query time reporting and planning.
"""
parent = aq_base(aq_parent(self))
threshold = getattr(parent, 'long_query_time', 0.1)
return CatalogReport(self, query, threshold)
return CatalogPlan(self, query, threshold)
class CatalogSearchArgumentsMap(object):
......
......@@ -103,7 +103,7 @@ class ZCatalog(Folder, Persistent, Implicit):
{'label': 'Metadata', 'action': 'manage_catalogSchema'},
{'label': 'Find Objects', 'action': 'manage_catalogFind'},
{'label': 'Advanced', 'action': 'manage_catalogAdvanced'},
{'label': 'Query Report', 'action': 'manage_catalogReport'},
{'label': 'Query Report', 'action': 'manage_catalogPlan'},
{'label': 'Undo', 'action': 'manage_UndoForm'},
{'label': 'Security', 'action': 'manage_access'},
{'label': 'Ownership', 'action': 'manage_owner'},
......@@ -127,9 +127,8 @@ class ZCatalog(Folder, Persistent, Implicit):
'manage_catalogAdvanced')
manage_catalogAdvanced = DTMLFile('dtml/catalogAdvanced', globals())
security.declareProtected(manage_zcatalog_entries,
'manage_catalogReport')
manage_catalogReport = DTMLFile('dtml/catalogReport', globals())
security.declareProtected(manage_zcatalog_entries, 'manage_catalogPlan')
manage_catalogPlan = DTMLFile('dtml/catalogPlan', globals())
security.declareProtected(manage_zcatalog_entries,
'manage_objectInformation')
......@@ -874,36 +873,36 @@ class ZCatalog(Folder, Persistent, Implicit):
def delColumn(self, name):
return self._catalog.delColumn(name)
# Catalog report methods
# Catalog plan methods
security.declareProtected(manage_zcatalog_entries, 'getCatalogReport')
def getCatalogReport(self):
""" Reports about the duration of queries """
rval = self._catalog.getCatalogReport().report()
security.declareProtected(manage_zcatalog_entries, 'getCatalogPlan')
def getCatalogPlan(self):
"""Query time reporting and planning."""
rval = self._catalog.getCatalogPlan().report()
rval.sort(key=operator.itemgetter('duration'), reverse=True)
return rval
security.declareProtected(manage_zcatalog_entries,
'manage_resetCatalogReport')
def manage_resetCatalogReport(self, REQUEST=None):
""" resets the catalog report """
self._catalog.getCatalogReport().reset()
'manage_resetCatalogPlan')
def manage_resetCatalogPlan(self, REQUEST=None):
"""Resets the catalog plan."""
self._catalog.getCatalogPlan().reset()
if REQUEST is not None:
REQUEST.response.redirect(REQUEST.URL1 +
'/manage_catalogReport?manage_tabs_message=Report%20cleared')
'/manage_catalogPlan?manage_tabs_message=Plan%20cleared')
security.declareProtected(manage_zcatalog_entries,
'manage_editCatalogReport')
def manage_editCatalogReport(self, long_query_time=0.1, REQUEST=None):
""" edit the long query time """
'manage_editCatalogPlan')
def manage_editCatalogPlan(self, long_query_time=0.1, REQUEST=None):
"""Edit the long query time."""
if not isinstance(long_query_time, float):
long_query_time = float(long_query_time)
self.long_query_time = long_query_time
if REQUEST is not None:
REQUEST.response.redirect(REQUEST.URL1 +
'/manage_catalogReport?manage_tabs_message=' +
'/manage_catalogPlan?manage_tabs_message=' +
'Long%20query%20time%20changed')
InitializeClass(ZCatalog)
......
......@@ -29,8 +29,8 @@
</div>
</td>
</tr>
<dtml-if getCatalogReport>
<dtml-in getCatalogReport mapping>
<dtml-if getCatalogPlan>
<dtml-in getCatalogPlan mapping>
<dtml-if sequence-odd>
<tr class="row-normal">
<dtml-else>
......@@ -68,7 +68,7 @@
<p class="form-help">Resetting the catalog report will reinitialize the report log.</p>
</td>
<td colspan="2" align="right" valign="top">
<form action="manage_resetCatalogReport" method=POST>
<form action="manage_resetCatalogPlan" method=POST>
<div class="form-element">
<input class="form-element" type="submit" value="Reset Report">
</div>
......@@ -86,7 +86,7 @@
</dtml-if>
</table>
<form action="manage_editCatalogReport" method="post">
<form action="manage_editCatalogPlan" method="post">
<table width="100%" style="padding-top:1em;" cellspacing="0" cellpadding="2" border="0">
<tr class="section-bar">
<td colspan="3" align="left">
......
......@@ -102,8 +102,9 @@ def make_key(catalog, query):
return key
class CatalogReport(object):
"""Catalog report class to meassure and identify catalog queries.
class CatalogPlan(object):
"""Catalog plan class to measure and identify catalog queries and plan
their execution.
"""
def __init__(self, catalog, query=None, threshold=0.1):
......
......@@ -26,7 +26,7 @@ class dummy(object):
return (self.num, self.num + 1)
class TestCatalogReport(unittest.TestCase):
class TestCatalogPlan(unittest.TestCase):
def setUp(self):
from Products.ZCatalog.ZCatalog import ZCatalog
......@@ -41,12 +41,12 @@ class TestCatalogReport(unittest.TestCase):
self.zcat.catalog_object(obj, str(i))
def tearDown(self):
from Products.ZCatalog.report import clear_value_indexes
from Products.ZCatalog.plan import clear_value_indexes
clear_value_indexes()
def test_ReportLength(self):
""" tests the report aggregation """
self.zcat.manage_resetCatalogReport()
self.zcat.manage_resetCatalogPlan()
self.zcat.searchResults(numbers=4, sort_on='num')
self.zcat.searchResults(numbers=1, sort_on='num')
......@@ -58,49 +58,49 @@ class TestCatalogReport(unittest.TestCase):
self.zcat.searchResults(num=[5, 4, 3], sort_on='num')
self.zcat.searchResults(num=(3, 4, 5), sort_on='num')
self.assertEqual(4, len(self.zcat.getCatalogReport()))
self.assertEqual(4, len(self.zcat.getCatalogPlan()))
def test_ReportCounter(self):
""" tests the counter of equal queries """
self.zcat.manage_resetCatalogReport()
self.zcat.manage_resetCatalogPlan()
self.zcat.searchResults(numbers=5, sort_on='num')
self.zcat.searchResults(numbers=6, sort_on='num')
self.zcat.searchResults(numbers=8, sort_on='num')
r = self.zcat.getCatalogReport()[0]
r = self.zcat.getCatalogPlan()[0]
self.assertEqual(r['counter'], 3)
def test_ReportKey(self):
""" tests the query keys for uniqueness """
# query key 1
key = ('sort_on', ('big', 'True'))
self.zcat.manage_resetCatalogReport()
self.zcat.manage_resetCatalogPlan()
self.zcat.searchResults(big=True, sort_on='num')
self.zcat.searchResults(big=True, sort_on='num')
r = self.zcat.getCatalogReport()[0]
r = self.zcat.getCatalogPlan()[0]
self.assertEqual(r['query'], key)
self.assertEqual(r['counter'], 2)
# query key 2
key = ('sort_on', ('big', 'False'))
self.zcat.manage_resetCatalogReport()
self.zcat.manage_resetCatalogPlan()
self.zcat.searchResults(big=False, sort_on='num')
r = self.zcat.getCatalogReport()[0]
r = self.zcat.getCatalogPlan()[0]
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.manage_resetCatalogPlan()
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]
r = self.zcat.getCatalogPlan()[0]
self.assertEqual(r['query'], key)
self.assertEqual(r['counter'], 2)
......@@ -108,5 +108,5 @@ class TestCatalogReport(unittest.TestCase):
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestCatalogReport))
suite.addTest(unittest.makeSuite(TestCatalogPlan))
return suite
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