entity - Deleting entities from app engine -


i'm going deleting entries python app engine server this:

    try:         while true:             q = db.gqlquery("select __key__ sampledata")             assert q.count()             db.delete(q.fetch(400))             time.sleep(0.2)         except exception, e:         self.response.out.write(repr(e)+'\n')         pass          try:         while true:             q = db.gqlquery("select __key__ userdata")             assert q.count()             db.delete(q.fetch(400))             time.sleep(0.2)         except exception, e:         self.response.out.write(repr(e)+'\n')         pass 

..but seems ugly , keep suspecting it's not entirely reliable. there way better delete entries of number of types instead of making 1 of each of these while loops?

update: 1 restriction have running periodically via cron job, not wish doing manually (i.e. via admin console instance).

a few improvements:

  1. you don't need sleep after each batch
  2. you should use task queue, , prepared chain task if don't finish time deadline hits.
  3. you should use cursors. if don't, subsequent queries have skip on 'tombstoned' rows you've deleted in order still existing rows.

if you're deleting or of kind, may want use mapreduce library instead.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -