David Johnson wrote:
Does anyone know the process by which objects are notified by events?

Objects aren't typically notified of events. Event handlers are. The whole event setup, including object events, is explained in detail in my book, http://worldcookery.com. I suggest picking up a copy :)

I created a custom container that stores objects in MySQL. However, I noticed that when I add a container that an ObjectAddedEvent is then propogated to every single object in my container, generating nearly 2000 queries. From my reading of the core Zope code, it seems that when an event is triggered it is sent to every single object in every container. This seems rather inefficient if you have either a large container or large objects in your container. Am I understanding this correctly?

To a degree. A common pattern in Zope is event dispatch. Dispatchers receive an event and propapage it further.

The container machinery has such a dispatcher for ObjectMovedEvents. When a container is moved, it propapates the event to its subobjects, so they know their overall physical location has changed. An ObjectAddedEvent is a special case of ObjectMovedEvent.

The problem seems to start in zope.app.container.contained.sublocations, which basically queries all objects in a container and sends an event to all of them.

You're probably talking about dispatchToSublocations. This is the code that looks up a containers sublocations and dispatches the event to them.

One way to prevent this behaviour for your container is to write a new ISublocations adapter for your container that simply returns an empty sequence:

  class MyContainerSublocations(object):

      def __init__(self, context):
          self.context = context

      def sublocations(self):
          return ()

http://worldcookery.com -- Professional Zope documentation and training
Next Zope 3 training at Camp5: http://trizpug.org/boot-camp/camp5

Zope3-users mailing list

Reply via email to