Actually count docs processed in dry-run, also make doubly sure we never perform anything.
diff --git a/tools/edit-list.py b/tools/edit-list.py
index fa69ac2..993644d 100755
--- a/tools/edit-list.py
+++ b/tools/edit-list.py
@@ -129,13 +129,16 @@
body['private'] = True
if args.makePublic:
body['private'] = False
- changes.append({
- '_op_type': 'delete' if args.deleteEmails else 'update',
- '_index': dbname,
- '_type': 'mbox',
- '_id': doc,
- 'doc': body
- })
+ if not args.dryrun:
+ changes.append({
+ '_op_type': 'delete' if args.deleteEmails else 'update',
+ '_index': dbname,
+ '_type': 'mbox',
+ '_id': doc,
+ 'doc': body
+ })
+ else:
+ changes.append({}) # Empty action for counting if dryrun, so we never accidentally run it.
return changes
def main():
@@ -221,14 +224,16 @@
# Handle proposed changes in batches of 500
while len(proposed_changes) > 0:
tmp.append(proposed_changes.pop(0))
- if len(tmp) == 500 and not args.dryrun:
- es.bulk(tmp)
+ if len(tmp) == 500:
+ if not args.dryrun:
+ es.bulk(tmp)
tmp = []
processed += 500
print("Processed %u documents..." % processed)
# Any stragglers remaining gets processed here
- if len(tmp) > 0 and not args.dryrun:
- es.bulk(tmp)
+ if len(tmp) > 0:
+ if not args.dryrun:
+ es.bulk(tmp)
processed += len(tmp)
print("Processed %u documents..." % processed)