I got tired of reindexing large indexes that were cleared unintelligently by the index import adapters so I wrote the following exportimport.pluginindexes and overrides.zcml. I'm posting them here in case anyone wants to use the code.
This doesn't handle reindexing indexes when it's needed but it does keep the adapters from needlessly clearing the indexes. Ross
"""Catalog index node adapters that only clear the index when needed.""" from Products.GenericSetup.PluginIndexes.exportimport import PluggableIndexNodeAdapter as PluggableIndexBase from Products.GenericSetup.PluginIndexes.exportimport import DateIndexNodeAdapter as DateIndexBase from Products.GenericSetup.PluginIndexes.exportimport import DateRangeIndexNodeAdapter as DateRangeIndexBase from Products.GenericSetup.PluginIndexes.exportimport import FilteredSetNodeAdapter as FilteredSetBase class PluggableIndexNodeAdapter(PluggableIndexBase): """Only clear the index when needed.""" def _importNode(self, node): """Import the object from the DOM node. """ indexed_attrs =  for child in node.childNodes: if child.nodeName == 'indexed_attr': indexed_attrs.append( child.getAttribute('value').encode('utf-8')) if getattr(self.context, 'indexed_attrs', None) != indexed_attrs: self.context.indexed_attrs = indexed_attrs self.context.clear() node = property(PluggableIndexBase._exportNode, _importNode) class DateIndexNodeAdapter(DateIndexBase): """Only clear the index when needed.""" def _importNode(self, node): """Import the object from the DOM node. """ if self.environ.shouldPurge(): self._purgeProperties() if node != self._extractProperties(): self._initProperties(node) self.context.clear() node = property(DateIndexBase._exportNode, _importNode) class DateRangeIndexNodeAdapter(DateRangeIndexBase): """Only clear the index when needed.""" def _importNode(self, node): """Import the object from the DOM node. """ since_field = node.getAttribute('since_field').encode('utf-8') until_field = node.getAttribute('until_field').encode('utf-8') if (self.context.getSinceField() != since_field or self.context.getUntilField() != until_field): self.context._edit(since_field, until_field) self.context.clear() node = property(DateRangeIndexBase._exportNode, _importNode) class FilteredSetNodeAdapter(FilteredSetBase): """Only clear the index when needed.""" def _importNode(self, node): """Import the object from the DOM node. """ expr = node.getAttribute('expression').encode('utf-8') if self.context.getExpression() != expr: self.context.setExpression(expr) self.context.clear() node = property(FilteredSetBase._exportNode, _importNode)
Description: Binary data
yuppie <[EMAIL PROTECTED]> writes: > Hi Stefan! > > > Stefan H. Holek wrote: >> On 17. Aug 2006, at 15:50, yuppie wrote: >> >>> My approach would be to improve the catalog adapters. Even if you >>> stick to the behavior implemented in setuphandlers.py it would have >>> been easier and more straight forward to implement it in a subclass >>> of ZCatalogXMLAdapter, overriding the default adapter. >>> >> >> I have tried this initially but found it impossible to "override" >> the existing adapter for IZCatalog. I always got complaints from the >> adapter machinery about duplicate registrations. I may be missing >> something here... > > Did you try it using an overrides.zcml file? Works for me - at least > with other adapters. > >>> But fixing some general catalog adapter issues will make your >>> special behavior obsolete: >>> >>> - The adapters should compare the new settings with the existing >>> ones and make sure indexes are only updated if they are actually >>> changed. This is not implemented so far. >>> >>> - The adapters should modify existing indexes if the profile >>> contains new settings. This is not implemented for the 'extra' >>> elements. >>> >>> - Reindexing might be very expensive. That's the reason why >>> GenericSetup does no reindexing, you have to do it manually. We >>> need a better solution for that, maybe some bookkeeping which >>> indexes need to be reindexed and a button in the setup tool that >>> triggers reindexing. >> >> +1 on all accounts > > As always: contributions are welcome... > > > Cheers, > > Yuppie > > _______________________________________________ > Zope-CMF maillist - Zope-CMF@lists.zope.org > http://mail.zope.org/mailman/listinfo/zope-cmf > > See http://collector.zope.org/CMF for bug reports and feature requests
_______________________________________________ Zope-CMF maillist - Zope-CMF@lists.zope.org http://mail.zope.org/mailman/listinfo/zope-cmf See http://collector.zope.org/CMF for bug reports and feature requests