[Zope-CMF] CMFCatalogAware.dispatchToOpaqueItems madness

Tres Seaver tseaver at palladion.com
Sat Dec 20 04:33:03 EST 2008


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Tres Seaver wrote:
> Matt Hamilton wrote:
>> I really don't understand this code, so maybe I'm missing something here, but
>> anyone know wtf the opaqueItem code does in CMFCore.CMFCatalogAware?!
> 
> It allows propagating IObjectEvents to nested objects not findable via
> the normal "content items" interface:  the one example in the CMF is the
> 'talkback' attribute which holds DiscussionItems for an object.
> 
>> Why does the opaqueItems method iterate through *every* attribute in the root of
>> the site causing all objects (including, at least in plone) all sub-objects of
>> folders to be woken up too):
> 
>>     for name in self_base.__dict__.keys():
>>             obj = getattr(self, name)
>>             if ICallableOpaqueItem.providedBy(obj) \
>>                     or z2ICallableOpaqueItem.isImplementedBy(obj):
>>                 items.append((obj.getId(), obj))
> 
>> If it is looking for opaque items (I still don't know what these really are)
>> then why does it look in content objects too?!
> 
> The 'opaqueItems' method in CMFCatalogAware is called only by the
> 'opaqueIds' and 'opaqueValues' methods in the same class.  The
> 'opaqueIds' method is never called in stock CMF at all.  The
> 'opaqueValues' method is called by the event subscriber which dispatches
> IObjectEvents.
> 
>> How about the changes below?
> 
>>     objectids = dict([(x,1) for x in self.objectIds()])                        
> 
>>     for name in self_base.__dict__.keys():
>>         if name not in objectids:                                              
> 
>>             obj = getattr(self, name)
>>             if ICallableOpaqueItem.providedBy(obj) \
>>                     or z2ICallableOpaqueItem.isImplementedBy(obj):
>>                 items.append((obj.getId(), obj))
> 
>> (that was probably all wrapped to hell)
> 
>> Basically, I've got a production site which loads up several tens of thousands
>> of objects from the ZODB just to display the front page.  Madness.
> 
> AFAIK, that stuff should have no impact on rendering the front page of
> your site:  the event handler should only be triggered on IObjectEvents
> emitted for an object, which will typically only be on writes.  You
> wouldn't be doing a write-on-read for every rendering of the homepage,
> would you?  If so, you have way worse problems than this bit of code.

OK, my bad here:  the *real* problem is that the event handler is
registered promiscuously for IObjectEvent, which turns out to get fired
a *lot*:  BeforeTraversal event is the one which is affecting you.

The *only* events of real interest for opaque subobjects are the "added"
/ "cloned" / "removed" events, which already have their own event
handler ('handleOpaqueItemEvent').  The BeforeTraversal event should not
be propagaged to subitems at all.

The attached patch registers that handler for only the objects it should
properly care about.  Can you verify that it makes your pain abate?

In any case, we need to review *all* of the event handlers registered
for IObjectEvent by the CMF.



Tres.
- --
===================================================================
Tres Seaver          +1 540-429-0999          tseaver at palladion.com
Palladion Software   "Excellence by Design"    http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFJTLvP+gerLs4ltQ4RAnnNAJ4sqG5LmmABuBWtNOA72O5FT5smTACdH/8Z
oUc8kMVUPVvt1wIhIH0h4OA=
=FkC7
-----END PGP SIGNATURE-----
-------------- next part --------------
A non-text attachment was scrubbed...
Name: right_opaque_events.diff
Type: text/x-patch
Size: 1122 bytes
Desc: not available
Url : http://mail.zope.org/pipermail/zope-cmf/attachments/20081220/71d28b10/attachment.bin 


More information about the Zope-CMF mailing list