[Zope-Coders] Traversing to a version (was: CMF/CMFStaging- Imported sources)

Brian Lloyd brian@zope.com
Thu, 16 May 2002 13:50:49 -0400


> > Ok thanks a lot. I hadn't looked deep enough at that part.
> > Thanks for the sample code too.
> > 
> > Very interesting indeed ;-)
> 
> One caution: getVersionOfResource() currently makes a copy in the 
> database every time you call it (so you can't accidentally change the 
> object that's actually stored in the repository).  So this traversal 
> hook would be pretty expensive.  I'm sure there's a way we can solve 
> this, and getVersionOfResource() is the right call to use, but before 
> putting anything into production you should keep this in mind.

Just to clarify, it doesn't make a copy _in_ the db, but it 
does make a copy _of_ the db object, which is slow (because 
it uses the low-level import/export mechanism) if abused.

getVersionOfResource is a helper that currently returns the 
state of the object as of the specified version, but with 
all database identity ties broken. The idea is that this is 
usually used to make the "working copy" of a resource from 
a particular version.

I _did_ have some play code laying around that allowed you 
to get at the version state in a read-only way (by replacing
the _p_jar of the version state with one that will always 
raise an error if you try to change the object). I could 
imagine refining the getVersionOfResource to look more like:

  def getVersionOfResource(self, history_id, selector, readonly=0):
     ...

...with the idea being that if you specifically pass the readonly 
flag then you can get the state much more efficiently, with the 
understanding that there is no way to change the object after 
you get it.

Not sure if this is the best way to do it though (you could 
do a totally separate method, getReadOnlyVersion or something), 
but I thought I'd throw out the idea for comment.


Brian Lloyd        brian@zope.com
V.P. Engineering   540.361.1716       
Zope Corporation   http://www.zope.com