Am I right in assuming that calls to objectValues etc. still return a real sequence of objects loaded in memory from ZODB? How about making object* calls return a generator instead? Has this been discussed somewhere already? I tried a bit of googling & list-searching but could not find much anything on this. Thanks, Petri
Petri Savolainen wrote:
Am I right in assuming that calls to objectValues etc. still return a real sequence of objects loaded in memory from ZODB? How about making object* calls return a generator instead? Has this been discussed somewhere already? I tried a bit of googling & list-searching but could not find much anything on this.
Funny you should ask, I played with something similar the other day. I wanted superValues-like functionality for CMF portal_types. Take a look at <http://svn.plone.org/view/collective/PloneboardPluggableDiscussion/trunk/utils.py?rev=10024&view=markup> for some rather inelegant looking code the implements this as an iterator. It's a bit different from what you're after as the gain isn't in the contentValues call (which is the equivalent of your objectValues), but rather in the fact that only the smallest number of those calls that are needed is made. Tim
Petri Savolainen wrote at 2005-8-4 19:01 +0300:
Am I right in assuming that calls to objectValues etc. still return a real sequence of objects loaded in memory from ZODB?
It depends. It is true for the standard folder, but it has anyway already loaded its complete content; therefore, the highest cost has already been paid whether or not you return a generator or not. Because of this behaviour, you should use such a folder only for moderately many items "BTreeFolder2" on the other hand already returns a generator -- although not a standard Python generator but a so call "LazyMap".
How about making object* calls return a generator instead?
I am against replacing "object*" return values by true Python generators because the do not support indexing (which I use occasionally). The change would be backward incompatible, the gain probably not worth this... -- Dieter
--On 4. August 2005 19:01:48 +0300 Petri Savolainen <petri.savolainen@iki.fi> wrote:
Am I right in assuming that calls to objectValues etc. still return a real sequence of objects loaded in memory from ZODB? How about making object* calls return a generator instead? Has this been discussed somewhere already? I tried a bit of googling & list-searching but could not find much anything on this.
If you use objectValues() then you should be aware that it loads every object from the ZODB. In the rare cases where I use objectValues() I am usually interested in every object and not only in some objects. As Dieter noticed implementing the functionality as generator would implement in incompatible behaviour so -1 for the proprosal changing the method itself. A dedicated method would be possible if you explain us some usecase where a generator would be more helpful. -aj
participants (4)
-
Andreas Jung -
Dieter Maurer -
Petri Savolainen -
Tim Hicks