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 da9bdbb Some fields are always required
da9bdbb is described below
commit da9bdbbfe0dd49fcd29e395639848d352af848a1
Author: Sebb <[email protected]>
AuthorDate: Tue Nov 23 10:01:17 2021 +0000
Some fields are always required
Also allow for empty list (which is False...)
---
server/endpoints/stats.py | 2 +-
server/plugins/messages.py | 16 +++++++++++++---
2 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/server/endpoints/stats.py b/server/endpoints/stats.py
index b25775c..b002e4e 100644
--- a/server/endpoints/stats.py
+++ b/server/endpoints/stats.py
@@ -59,7 +59,7 @@ async def process(
query_since = query_defuzzed.copy()
query_since['must'].append({"range" : { "epoch": { "gt": epoch}}})
results = await plugins.messages.query(
- session, query_since, query_limit=1, source_fields=[''] # don't
need any fields
+ session, query_since, query_limit=1, source_fields=[] # don't need
any fields
)
if len(results) == 0:
return {"changed" : False}
diff --git a/server/plugins/messages.py b/server/plugins/messages.py
index b9df057..b846e32 100644
--- a/server/plugins/messages.py
+++ b/server/plugins/messages.py
@@ -333,10 +333,15 @@ async def query(
"query": {"bool": query_defuzzed},
"sort": [{"epoch": {"order": epoch_order}}],
}
+ # must fetch private and deleted
+ MUST_HAVE = [ 'private', 'deleted']
if metadata_only: # Only doc IDs and AAA fields.
es_query["_source"] = ["deleted", "private", "mid", "dbid", "list_raw"]
- elif source_fields:
- es_query["_source"] = source_fields
+ elif not source_fields is None:
+ es_query["_source"] = source_fields.copy()
+ for hdr in MUST_HAVE:
+ if not hdr in source_fields:
+ es_query["_source"].append(hdr)
else:
es_query["_source"] = { "excludes": ["body"] }
async for hit in session.database.scan(
@@ -351,7 +356,7 @@ async def query(
if "mid" in doc: # might be missing when using source_fields
doc["id"] = doc["mid"]
# Calculate gravatars if not present in source
- if not metadata_only and not source_fields and "gravatar" not in
doc:
+ if not metadata_only and source_fields is None and "gravatar" not
in doc:
doc["gravatar"] = gravatar(doc)
if not session.credentials:
doc = anonymize(doc)
@@ -365,6 +370,11 @@ async def query(
# stats.py is expecting doc['body'], not body_short
del doc["body_short"]
trim_email(doc)
+ # drop any added fields
+ if not source_fields is None:
+ for hdr in MUST_HAVE:
+ if not hdr in source_fields:
+ del doc[hdr]
docs.append(doc)
hits += 1
if hits > query_limit: