You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Sep 2, 2021. It is now read-only.
In my code I sometimes have to go thought all objects of a certain type. By using the DBObject.all() function it seems all objects are instantiated in a large array. Would it be possible to have all() or find() return a generator function, so that code like
for object in Object.all():
object.doSomething()
would involve only one instance of Object at a time, which could be garbage collected after each iteration in the loop?
Jan-Pascal
The text was updated successfully, but these errors were encountered:
That could work, but it wouldn't be able to function like a true generator. For instance, you wouldn't be able to do:
foroinMyObject.all(generator=True):
printo.name
It could maybe be done as a class method that takes a function that is called with a list of objects at a time (like find_in_batches in ActiveRecord). That would look something like:
defprint_names(olist):
foroinolist:
printo.name# may return a deferreddefdone():
print"Finished finding and printing everything"MyObject.find_in_batches(print_names).addCallback(done)
But it would have to be done carefully to not blow out the call stack if there are a ton of calls.
I like the find_in_batches pattern. It would suit my needs, and it looks
like a clean interface, especially if you could give it an optional
batch_size argument.
Hi,
In my code I sometimes have to go thought all objects of a certain type. By using the DBObject.all() function it seems all objects are instantiated in a large array. Would it be possible to have all() or find() return a generator function, so that code like
for object in Object.all():
object.doSomething()
would involve only one instance of Object at a time, which could be garbage collected after each iteration in the loop?
Jan-Pascal
The text was updated successfully, but these errors were encountered: