Re: [Zope-dev] Reg. updating catalog indexes in bluebream
Thierry Florac <[email protected]>
| Newsgroups | gmane.comp.web.zope.bluebream,gmane.comp.web.zope.devel |
|---|---|
| Message-ID | <[email protected]> |
Le Thu, 23 Jun 2011 21:49:34 +0530, Joshua Immanuel <[email protected]> a �crit: > On Thu, 2011-06-23 at 17:19 +0200, Charlie Clark wrote: > > The indices do have to be updated every time you add, delete or > > modify an object. This is one of the reasons for the event system > > you were asking about the other week. > > As the size of sm['intids'] were getting incremented as and when new > objects were added, without me doing anything explicitly about it. I > was of the notion that I don't need to explicitly update the indexes. If added object implements ILocation, ObjectAddedEvent subscriber generates an automatic IntId registration, and a new IntIdAddedEvent event is fired, which is catched by Catalog indexDocSubscriber to handle automatic cataloging of added objects. ObjectModifiedEvent event is directly handled by Catalog reindexDocSubscriber to handle index updates. > If I subscribe for 'IContainerModifiedEvent' for the container of > 'Client' object and update the indexes, then I think I'll miss out if > just the attributes of 'Client' object is modified. So, I think along > with this I should subscribe for 'IObjectModifiedEvent' of 'Client' > object. > > Will this be sufficient? Is there any other better way of doing this? You don't have to subscribe to IContainerModifiedEvent or IObjectModifiedEvent: zope.intid and zope.catalog packages already provide subscribers for these events to automatically handle updates of indexes. What you have to do is just to generate an ObjectAddedEvent or ObjectModifiedEvent when your object is added or modified, and notify subscribers for it: myEvent = ObjectModifiedEvent(myObject) notify(myEvent) Most form handling packages (zope.formlib, z3c.form) automatically handle these events notifications if their base classes. Regards, Thierry
signature.asc
(application/pgp-signature, 198 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) iEYEARECAAYFAk4DujUACgkQN1cBzqEzSpnvlwCgpbgU8uHSQb7p0ZqJ8l6L2KsY FV4An2v/V08da9cwx/w+/usG8ql62ukv =UCPr -----END PGP SIGNATURE-----