[Zope] automagic reindexing of objects

Paul Winkler pw_lists at slinkp.com
Fri Jun 17 12:54:23 EDT 2005


On Fri, Jun 17, 2005 at 02:19:26PM +0200, J?rgen Herrmann wrote:
> hi all!
> 
> i make heavy use of indexes in my extension classes. these all inherit
> from catalogpathaware, so i have to call object.reindex_object() on
> each changed instance. calling it from attribute getters/setters f.ex.
> is not a good idea, because changing 3 attributes will reindex the object
> 3 times.
> 
> what i'd like to have is that such objects are reindexed automatically
> before comitting a transaction.
> 
> is it possible? where should i start looking in the source, is there
> possibly a before_transaction_commit hook?

I vaguely recall a similar discussion on zodb-dev; a search of the 
archives of that list may be a good idea.

You might also find QueueCatalog useful. AFAICT, if you are
using QueueCatalog and an object asks to be reindexed three times
before the next time the queue is processed, the QueueCatalog will
only actually reindex the object once. The tradeoff is that the
catalog results can be stale. 

It's only available via CVS, and doesn't come with docs, but
the embedded docstrings look pretty good. Note, I haven't used
it yet myself.
http://cvs.zope.org/Products/QueueCatalog/
Or to get a tarball,
http://cvs.zope.org/Products/QueueCatalog/QueueCatalog.tar.gz?tarball=1


It looks like you need some external process to actually 
trigger the processing of the queue.  A cron job calling a wget script
would do the job, or (better imho because it runs as a separate process)
if you are using zeo you could run a pretty trivial python script 
via bin/zopectl ... something like (untested):

import time
while 1:
    time.sleep(30)
    events_count = app.path.to.my.queuecatalog.process(max=1000)
    print "processed %d events" % events_count  # or log it somewhere.

Hope that helps, 
-PW

-- 

Paul Winkler
http://www.slinkp.com


More information about the Zope mailing list