The first approach normally should work. But there is also a very very
small possibility that some of fetched entries are updated during this
call, which will cause the updated values being deleted.

The second approach doesn't actually work on GAE, because query isn't
supported inside a transaction. Here is an updated transaction
version.
def txn(key):
    old = db.get(key)
    if old is not None and old.atime < expire_time:
        old.delete()
for old in table.all().filter('atime <', expire_time):
    db.run_in_transaction(old.key())

This is even more inefficent, because same entry need to be fetch
twice, one for query and one for verifying inside transaction.

On Oct 23, 6:09 pm, Jeff S <[EMAIL PROTECTED]> wrote:
> Hi yejun,
>
> I didn't see any immediate problems with the first approach which you
> listed, I agree it will be more efficient than the second approach.
> Depending on the shape of your data you might need to adjust the
> number of items which you fetch and delete in a single request (100
> could be too many to try to delete in one request in some cases).
>
> The second approach listed will probably be slower, since a delete
> with multiple entities may be able to perform deletes in parallel. It
> also seems like the loop will run until one of the transactions fails
> which might be too long for the HTTP request to return a result within
> the alloted time.
>
> Thank you,
>
> Jeff
>
> On Oct 22, 1:56 pm, yejun <[EMAIL PROTECTED]> wrote:
>
> > The model is very simple here.
> > class table(db.Model)
> >     atime=db.DateTimeProperty(auto_now=True)
> >     data=db.BlobProperty()
>
> > I want to have function simply delete data older than a certain time.
>
> > Is it safe to use just
>
> > db.delete(table.all().filter('atime <', expire_time).fetch(100))
>
> > or do I have to do it like this
>
> > def txn():
> >     old = table.all().filter('atime <', expire_time).get()
> >     if old is not None:
> >         old.delete()
> >         return True
> >     return False
> > while run_in_transaction(txn): pass
>
> > My concern is that the first method may delete an entry is being
> > updated. The second method seems very inefficient.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to