You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ponymail.apache.org by se...@apache.org on 2022/01/28 21:45:02 UTC

[incubator-ponymail-foal] 01/02: Ensure changes are flushed for testing

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

commit 1ad478fdca6f9f66ac192941082995d83b965b9d
Author: Sebb <se...@apache.org>
AuthorDate: Fri Jan 28 21:44:26 2022 +0000

    Ensure changes are flushed for testing
---
 server/endpoints/mgmt.py | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/server/endpoints/mgmt.py b/server/endpoints/mgmt.py
index 7a4b143..61bcf5f 100644
--- a/server/endpoints/mgmt.py
+++ b/server/endpoints/mgmt.py
@@ -24,6 +24,10 @@ import plugins.auditlog
 import typing
 import aiohttp.web
 
+# N.B. the update/delete database operations are performed with the setting refresh='wait_for'
+# This is was done to make testing easier.
+# There are very few such changes so this should not affect performance unduly
+
 
 async def process(
     server: plugins.server.BaseServer, session: plugins.session.SessionObject, indata: dict,
@@ -59,15 +63,15 @@ async def process(
                     del email["id"]
                 if server.config.ui.fully_delete and email["mid"] and email["dbid"]:  # Full on GDPR blast?
                     await session.database.delete(
-                        index=session.database.dbs.db_mbox, id=email["mid"],
+                        index=session.database.dbs.db_mbox, id=email["mid"], refresh='wait_for',
                     )
                     await session.database.delete(
-                        index=session.database.dbs.db_source, id=email["dbid"],
+                        index=session.database.dbs.db_source, id=email["dbid"], refresh='wait_for',
                     )
                 else:  # Standard behavior: hide the email from everyone.
                     email["deleted"] = True
                     await session.database.update(
-                        index=session.database.dbs.db_mbox, body={"doc": email}, id=email["mid"],
+                        index=session.database.dbs.db_mbox, body={"doc": email}, id=email["mid"], refresh='wait_for',
                     )
                 lid = email.get("list_raw", "??")
                 await plugins.auditlog.add_entry(session, action="delete", target=doc, lid=lid, log=f"Removed email {doc} from {lid} archives")
@@ -84,7 +88,7 @@ async def process(
                     del email["id"]
                 email["deleted"] = True
                 await session.database.update(
-                    index=session.database.dbs.db_mbox, body={"doc": email}, id=email["mid"],
+                    index=session.database.dbs.db_mbox, body={"doc": email}, id=email["mid"], refresh='wait_for',
                 )
                 lid = email.get("list_raw", "??")
                 await plugins.auditlog.add_entry(session, action="hide", target=doc, lid=lid, log=f"Hid email {doc} from {lid} archives")
@@ -101,7 +105,7 @@ async def process(
                     del email["id"]
                 email["deleted"] = False
                 await session.database.update(
-                    index=session.database.dbs.db_mbox, body={"doc": email}, id=email["mid"],
+                    index=session.database.dbs.db_mbox, body={"doc": email}, id=email["mid"], refresh='wait_for',
                 )
                 lid = email.get("list_raw", "??")
                 await plugins.auditlog.add_entry(session, action="unhide", target=doc, lid=lid, log=f"Unhid email {doc} from {lid} archives")
@@ -123,7 +127,7 @@ async def process(
 
             if attachment and isinstance(attachment, dict):
                 await session.database.delete(
-                    index=session.database.dbs.db_attachment, id=attachment["_id"],
+                    index=session.database.dbs.db_attachment, id=attachment["_id"], refresh='wait_for',
                 )
                 lid = "<system>"
                 await plugins.auditlog.add_entry(session, action="delatt", target=doc, lid=lid, log=f"Removed attachment {doc} from the archives")
@@ -178,7 +182,7 @@ async def process(
             if "id" in email: # id is not a valid property for mbox
                 del email["id"]
             await session.database.update(
-                index=session.database.dbs.db_mbox, body={"doc": email}, id=email["mid"],
+                index=session.database.dbs.db_mbox, body={"doc": email}, id=email["mid"], refresh='wait_for',
             )
 
             # Fetch source, mark as deleted (modified) and save IF anything but just privacy changed
@@ -190,7 +194,7 @@ async def process(
                     source = source["_source"]
                     source["deleted"] = True
                     await session.database.update(
-                        index=session.database.dbs.db_source, body={"doc": source}, id=docid,
+                        index=session.database.dbs.db_source, body={"doc": source}, id=docid, refresh='wait_for',
                     )
 
             await plugins.auditlog.add_entry(session, action="edit", target=doc, lid=lid,