[Checkins] SVN: Products.ZCatalog/trunk/ Add a progress handler to the addColumn and delColumn methods
Hano Schlichting
cvs-admin at zope.org
Sat Apr 7 12:18:59 UTC 2012
Log message for revision 125063:
Add a progress handler to the addColumn and delColumn methods
Changed:
U Products.ZCatalog/trunk/CHANGES.txt
U Products.ZCatalog/trunk/src/Products/ZCatalog/Catalog.py
U Products.ZCatalog/trunk/src/Products/ZCatalog/ZCatalog.py
U Products.ZCatalog/trunk/src/Products/ZCatalog/tests/test_catalog.py
-=-
Modified: Products.ZCatalog/trunk/CHANGES.txt
===================================================================
--- Products.ZCatalog/trunk/CHANGES.txt 2012-04-07 11:59:52 UTC (rev 125062)
+++ Products.ZCatalog/trunk/CHANGES.txt 2012-04-07 12:18:56 UTC (rev 125063)
@@ -4,6 +4,10 @@
3.0 (unreleased)
----------------
+- Added a `threshold` argument to the catalog's `addColumn` and `delColumn`
+ methods and used it for a progress handler. Also optimized some of their
+ internals.
+
- Added support for simple `sort_on` queries with two sort indexes. The
`sort_order` is currently single valued and applies to both of them. But a
query like: `{'foo': 'a', 'sort_on':['foo', 'bar']}` is supported now.
Modified: Products.ZCatalog/trunk/src/Products/ZCatalog/Catalog.py
===================================================================
--- Products.ZCatalog/trunk/src/Products/ZCatalog/Catalog.py 2012-04-07 11:59:52 UTC (rev 125062)
+++ Products.ZCatalog/trunk/src/Products/ZCatalog/Catalog.py 2012-04-07 12:18:56 UTC (rev 125063)
@@ -35,6 +35,7 @@
from .Lazy import LazyMap, LazyCat, LazyValues
from .CatalogBrains import AbstractCatalogBrain, NoBrainer
from .plan import CatalogPlan
+from .ProgressHandler import ZLogHandler
LOG = logging.getLogger('Zope.ZCatalog')
@@ -152,7 +153,7 @@
self._v_brains = brains
self._v_result_class = mybrains
- def addColumn(self, name, default_value=None):
+ def addColumn(self, name, default_value=None, threshold=10000):
"""
adds a row to the meta data schema
"""
@@ -176,8 +177,12 @@
if default_value in (None, ''):
default_value = MV
- for key, value in self.data.iteritems():
+ pghandler = ZLogHandler(threshold)
+ pghandler.init('Adding %s column' % name, len(self))
+ for i, (key, value) in enumerate(self.data.iteritems()):
+ pghandler.report(i)
self.data[key] = value + (default_value, )
+ pghandler.finish()
self.names = tuple(names)
self.schema = schema
@@ -187,7 +192,7 @@
self._p_changed = 1 # why?
- def delColumn(self, name):
+ def delColumn(self, name, threshold=10000):
"""
deletes a row from the meta data schema
"""
@@ -214,10 +219,12 @@
# remove the column value from each record
_next_index = _index + 1
- for key, value in self.data.iteritems():
- rec = list(value)
- del rec[_index]
+ pghandler = ZLogHandler(threshold)
+ pghandler.init('Deleting %s column' % name, len(self))
+ for i, (key, value) in enumerate(self.data.iteritems()):
+ pghandler.report(i)
self.data[key] = value[:_index] + value[_next_index:]
+ pghandler.finish()
def addIndex(self, name, index_type):
"""Create a new index, given a name and a index_type.
Modified: Products.ZCatalog/trunk/src/Products/ZCatalog/ZCatalog.py
===================================================================
--- Products.ZCatalog/trunk/src/Products/ZCatalog/ZCatalog.py 2012-04-07 11:59:52 UTC (rev 125062)
+++ Products.ZCatalog/trunk/src/Products/ZCatalog/ZCatalog.py 2012-04-07 12:18:56 UTC (rev 125063)
@@ -881,11 +881,12 @@
security.declareProtected(manage_zcatalog_indexes, 'addColumn')
def addColumn(self, name, default_value=None):
- return self._catalog.addColumn(name, default_value)
+ return self._catalog.addColumn(name, default_value,
+ threshold=self.threshold)
security.declareProtected(manage_zcatalog_indexes, 'delColumn')
def delColumn(self, name):
- return self._catalog.delColumn(name)
+ return self._catalog.delColumn(name, threshold=self.threshold)
# Catalog plan methods
Modified: Products.ZCatalog/trunk/src/Products/ZCatalog/tests/test_catalog.py
===================================================================
--- Products.ZCatalog/trunk/src/Products/ZCatalog/tests/test_catalog.py 2012-04-07 11:59:52 UTC (rev 125062)
+++ Products.ZCatalog/trunk/src/Products/ZCatalog/tests/test_catalog.py 2012-04-07 12:18:56 UTC (rev 125063)
@@ -101,13 +101,24 @@
catalog = self._makeOne()
self.assertRaises(CatalogError, catalog.addColumn, '_id')
+ def test_add_brains(self):
+ catalog = self._makeOne()
+ catalog.addColumn('col1')
+ catalog.addColumn('col3')
+ for i in xrange(3):
+ catalog.catalogObject(dummy(3), repr(i))
+ self.assertTrue('col2' not in catalog.data.values()[0])
+ catalog.addColumn('col2', default_value='new')
+ self.assert_('col2' in catalog.schema, 'add column failed')
+ self.assertTrue('new' in catalog.data.values()[0])
+
def test_del(self):
catalog = self._makeOne()
catalog.addColumn('id')
catalog.delColumn('id')
self.assert_('id' not in catalog.schema, 'del column failed')
- def test_del_remaining(self):
+ def test_del_brains(self):
catalog = self._makeOne()
catalog.addColumn('col1')
catalog.addColumn('col2')
More information about the checkins
mailing list