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