bulk-delete docs twisty
authorMark Hammond <mhammond@skippinet.com.au>
Sat, 28 Mar 2009 17:32:59 +1100
branchtwisty
changeset 129 8704eacfbfb6f0baad8d6202fee770c10491d350
parent 128 f95653d4377dcb27c75805dd631523d86d2c38f3
child 130 170cf0cb11a2234bb68fbc11933bc7913a0ca503
push id1
push userroot
push dateWed, 08 Apr 2009 01:46:05 +0000
bulk-delete docs
server/python/run-raindrop.py
--- a/server/python/run-raindrop.py
+++ b/server/python/run-raindrop.py
@@ -60,42 +60,39 @@ def process(result, parser, options):
 
 def delete_docs(result, parser, options):
     """Delete all documents of a particular type.  Use with caution"""
     # NOTE: This is for development only, until we get a way to say
     # 'reprocess stuff you've already done' - in the meantime deleting those
     # intermediate docs has the same result...
     from urllib import quote
     db = model.get_db()
-    # use a semaphore so we don't overload things...
-    d_sem = defer.DeferredSemaphore(4)
+
     def _del_docs(to_del):
-        deferreds = []
+        docs = []
         for id, rev in to_del:
-            d = d_sem.run(db.deleteDoc, id, rev)
-            deferreds.append(d)
-        return defer.DeferredList(deferreds)
+            docs.append({'_id': id, '_rev': rev, '_deleted': True})
+        return db.updateDocuments(docs)
 
     def _got_docs(result, dt):
-        to_del = [(quote(row['id'], safe=''), row['value']) for row in result]
+        to_del = [(row['id'], row['value']) for row in result]
         logger.info("Deleting %d documents of type %r", len(to_del), dt)
         return to_del
 
     if not options.doctypes:
         parser.error("You must specify one or more --doctype")
     deferreds = []
     for dt in options.doctypes:
-        d = d_sem.run(
-                db.openView, 'raindrop!messages!by', 'by_doc_type', key=dt
+        d = db.openView('raindrop!messages!by', 'by_doc_type', key=dt
                 ).addCallback(_got_docs, dt
                 ).addCallback(_del_docs
                 )
         deferreds.append(d)
+    return defer.DeferredList(deferreds)
 
-    return defer.DeferredList(deferreds)
 
 def _setup_logging(options):
     init_errors = []
     logging.basicConfig()
     for val in options.log_level: # a list of all --log-level options...
         try:
             name, level = val.split("=", 1)
         except ValueError: