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 ce8ba88  Add support for since to stats.py
ce8ba88 is described below

commit ce8ba88e0c09b4975666d045e3949e18b8e08147
Author: Sebb <[email protected]>
AuthorDate: Fri Nov 19 17:11:36 2021 +0000

    Add support for since to stats.py
    
    This fixes #110
---
 server/endpoints/stats.py | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/server/endpoints/stats.py b/server/endpoints/stats.py
index 09d3ce8..dbf6e4c 100644
--- a/server/endpoints/stats.py
+++ b/server/endpoints/stats.py
@@ -48,6 +48,22 @@ async def process(
         return aiohttp.web.Response(headers={"content-type": "text/plain",}, 
status=400, text=str(ve))
     except AssertionError as ae:  # If defuzzer encounters internal errors, it 
will throw an AssertionError
         return aiohttp.web.Response(headers={"content-type": "text/plain",}, 
status=500, text=str(ae))
+    
+    # since: check if there have been recent updates to the data
+    if 'since' in indata:
+        since = indata.get('since', None)
+        if since:
+            epoch = int(since)
+        else:
+            epoch = int(time.time())
+        query_since = query_defuzzed.copy()
+        query_since['must'].append({"range" : { "epoch": { "gt": epoch}}})
+        results = await plugins.messages.query(
+            session, query_since, query_limit=1, metadata_only=True
+        )
+        if len(results) == 0:
+            return {"changed" : False}
+
     results = await plugins.messages.query(
         session, query_defuzzed, query_limit=server.config.database.max_hits
     )

Reply via email to