Changes between Version 11 and Version 12 of AppEngine
- Timestamp:
- Feb 25, 2009, 6:33:32 AM (16 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
AppEngine
v11 v12 63 63 == Datastore batch operations == 64 64 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. 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. 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. 66 66 67 67 The 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. 68 68 69 There are batch operations for getting lots of model instances by key. This could be emulated with 69 Certain batch operations can already be emulated with the existing API: 70 71 Getting lots of model instances by key: 70 72 71 73 {{{ 72 MyModel.objects.all().filter(pk__in=[key1, key2, ...])74 Blog.objects.all().filter(pk__in=[key1, key2, ...]) 73 75 }}} 76 77 Deleting a set of rows by key: 78 79 {{{ 80 Blog.objects.all().filter(pk__in=[key1, key2, ...]).delete() 81 }}} 82 83 Changing existing rows: 84 85 {{{ 86 Blog.objects.all().filter(pk__in=[key1, key2, ...]).update(title='My Blog') 87 }}} 88 74 89 75 90 == Model relations and JOINs ==