Changes between Version 11 and Version 12 of AppEngine


Ignore:
Timestamp:
02/25/2009 06:33:32 AM (6 years ago)
Author:
wkornewald
Comment:

clarified batch operations

Legend:

Unmodified
Added
Removed
Modified
  • AppEngine

    v11 v12  
    6363== Datastore batch operations ==
    6464
    65 Datastore writes are very expensive. App Engine provides batch operations for saving and deleting lots of model instances at once (no more than 500 entries, though). Django should provide such an API, too, so code can be optimized.
     65Datastore writes are very expensive. App Engine provides batch operations for saving and deleting lots of model instances at once (no more than 500 entries, though). Django should provide such an API, too, so code can be optimized. Note that while Django does support a few batch operations they work at the DB level, so the model instances' save() and delete() methods are never called.
    6666
    6767The API would be most flexible if it worked like a transaction handler where all save() calls within a function call are collected and then committed afterwards. The implementation wouldn't be trivial, though. It requires maintaining a cache of to-be-saved instances, so filter() calls can check the cache. Also, when a real transaction starts the cache must be flushed and disabled because in transactions we have to interact with the DB directly in order to lock an entity group. Instead of a decorator we could also provide a middleware, but this could lead to problems if, for instance, the view issues an http request (e.g., to start a task) and thus requires that the data has already been stored.
    6868
    69 There are batch operations for getting lots of model instances by key. This could be emulated with
     69Certain batch operations can already be emulated with the existing API:
     70
     71Getting lots of model instances by key:
    7072
    7173{{{
    72 MyModel.objects.all().filter(pk__in=[key1, key2, ...])
     74Blog.objects.all().filter(pk__in=[key1, key2, ...])
    7375}}}
     76
     77Deleting a set of rows by key:
     78
     79{{{
     80Blog.objects.all().filter(pk__in=[key1, key2, ...]).delete()
     81}}}
     82
     83Changing existing rows:
     84
     85{{{
     86Blog.objects.all().filter(pk__in=[key1, key2, ...]).update(title='My Blog')
     87}}}
     88
    7489
    7590== Model relations and JOINs ==
Back to Top