Humbedooh commented on a change in pull request #60:
URL: 
https://github.com/apache/incubator-ponymail-foal/pull/60#discussion_r711776068



##########
File path: server/plugins/messages.py
##########
@@ -445,26 +445,36 @@ async def get_years(session, query_defuzzed):
             {"bool": {"should": [{"term": {"private": False}}, {"terms": 
{"list_raw": private_lists_accessible}}]}}
         ]
 
-    # Get oldest and youngest doc in single scan
+    # Get oldest and youngest doc in single scan, as well as a monthly 
histogram
     res = await session.database.search(
         index=session.database.dbs.mbox,
         size=0,
         body={"query": {"bool": query_defuzzed},
             "aggs": {
                 "first": {"min": {"field": "epoch"}},
                 "last": {"max": {"field": "epoch"}},
+                "active_months": {
+                    "date_histogram": {
+                        "field": "date",
+                        "calendar_interval": "month",
+                        "format": "yyyy-MM"
+                    }
+                }
             },
         }
     )
 
     oldest = datetime.datetime.fromtimestamp(0)
     youngest = datetime.datetime.fromtimestamp(0)
+    monthly_activity = {}
     if res["aggregations"]:
         aggs = res["aggregations"]
         oldest = datetime.datetime.fromtimestamp(aggs["first"]["value"] or 0)
         youngest = datetime.datetime.fromtimestamp(aggs["last"]["value"] or 0)
+        for bucket in aggs["active_months"].get("buckets", []):
+            monthly_activity[bucket["key_as_string"]] = bucket["doc_count"]

Review comment:
       Good idea, done.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to