This is an automated email from the ASF dual-hosted git repository.

sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ponymail-foal.git


The following commit(s) were added to refs/heads/master by this push:
     new a134a3e  Don't accumulate entries for dry runs
a134a3e is described below

commit a134a3e07b8e9f748f8789ed8eef13b8731c2f37
Author: Sebb <[email protected]>
AuthorDate: Sat Nov 27 14:34:59 2021 +0000

    Don't accumulate entries for dry runs
---
 tools/import-mbox.py | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/tools/import-mbox.py b/tools/import-mbox.py
index f53821d..ed3b48b 100755
--- a/tools/import-mbox.py
+++ b/tools/import-mbox.py
@@ -370,21 +370,24 @@ class SlurpThread(Thread):
                         continue
 
                     count += 1
-                    ja.append(json)
-                    jas.append(json_source)
                     if args.verbose and verbose_logger:
                         # TODO optionally show other fields (e.g. From_ line)
                         verbose_logger.info("MID:%(mid)s 
MSGID:%(message-id)s", json)
+
+                    # Nothing more to do if dry run
+                    if args.dry:
+                        continue
+                    ja.append(json)
+                    jas.append(json_source)
                     if contents:
-                        if not args.dry:
-                            for key in contents:
-                                es.index(
-                                    index=es.db_attachment,
-                                    doc_type="_doc",
-                                    id=key,
-                                    body={"source": contents[key]},
-                                )
-                    if len(ja) >= 40 and not args.dry:
+                        for key in contents:
+                            es.index(
+                                index=es.db_attachment,
+                                doc_type="_doc",
+                                id=key,
+                                body={"source": contents[key]},
+                            )
+                    if len(ja) >= 40:
                         bulk_insert(self.name, ja, es, es.db_mbox)
                         ja = []
 
@@ -414,6 +417,7 @@ class SlurpThread(Thread):
 
             goodies += count
             baddies += bad
+            print(len(ja))
             if len(ja) > 0 and not args.dry:
                 bulk_insert(self.name, ja, es, es.db_mbox)
             ja = []

Reply via email to