Christian Heimes <heimes@faho.rwth-aachen.de> wrote:
Florent Guillaume wrote:
I really could use a post publishing hook. Standard use case: delay indexing at the end of the request to only do it once per object even if the object has been modified 4 times.
Using a post publishing hook for this use case isn't a good idea - IMO. The Publisher has nothing to with indexing. It's a completly different part of the architecture.
You want to bind some actions to the transaction system because you want to execute some code at the end of the first phase of the 2 phase commit. That's a completly different story than the post publishing hook. Hooking into the transaction machinery of ZODB is very easy. Write your own DateManager implementing the IDateManager interface and register it into the current transaction using get_transaction.register(DM). [note: s/IDateManager/IDataManager/ above]
For your use case overwrite the tpc_vote() method of the data manager to do the indexing at the boundary between the two phases.
Jens Vagenpohl's mail host and Chris McD's blob have example code for you.
Ok, Tres also recommended something like that. I was a bit concerned that there would be problems in case of conflicts, or if there was a need to tweak the body returned to the user, but after reading transaction's code and MailDropHost and re-re-reading Publisher.py, I'm confident I can do everything I need. Thanks a lot, this together with events will make things much easier in our framework. Florent -- Florent Guillaume, Nuxeo (Paris, France) CTO, Director of R&D +33 1 40 33 71 59 http://nuxeo.com fg@nuxeo.com