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 2016/12/11 02:18:34 UTC

[1/2] incubator-ponymail git commit: stats.lua could use single aggregate query to get first and last years

Repository: incubator-ponymail
Updated Branches:
  refs/heads/master 0cb3f31a4 -> 68ea3726e


stats.lua could use single aggregate query to get first and last years

This fixes #276

Project: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/commit/36e6d594
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/tree/36e6d594
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/diff/36e6d594

Branch: refs/heads/master
Commit: 36e6d59445d58ccd55c19eb14cc6bb7d7c816f8a
Parents: 0cb3f31
Author: Sebb <se...@apache.org>
Authored: Sun Dec 11 01:35:41 2016 +0000
Committer: Sebb <se...@apache.org>
Committed: Sun Dec 11 01:35:41 2016 +0000

----------------------------------------------------------------------
 CHANGELOG.md       |  1 +
 site/api/stats.lua | 61 +++++++++++++++----------------------------------
 2 files changed, 19 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/36e6d594/CHANGELOG.md
----------------------------------------------------------------------
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 21c175a..372f60b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -53,6 +53,7 @@
 - stored date uses locale-dependent conversion and is ambiguous (#86)
 - search strings not properly quoted. (#76)
 - pminfo.lua creates top100 sender information but it's not used (#282)
+- stats.lua could use single aggregate query to get first and last years (#276)
 
 ## CHANGES in 0.9b:
 

http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/36e6d594/site/api/stats.lua
----------------------------------------------------------------------
diff --git a/site/api/stats.lua b/site/api/stats.lua
index 61074a9..6fa0da3 100644
--- a/site/api/stats.lua
+++ b/site/api/stats.lua
@@ -445,41 +445,12 @@ function handle(r)
     -- Get years active
     local NOWISH = math.floor(os.time()/600)
     local FIRSTYEAR_KEY = "firstYear:" .. NOWISH .. ":" .. get.list .. "@" .. get.domain
-    local firstYear = r:ivm_get(FIRSTYEAR_KEY)
-    if (not firstYear or firstYear == "") and not statsOnly then
-        local doc = elastic.raw {
-            query = {
-                bool = {
-                    must = {
-                        {
-                            range = {
-                                date = {
-                                    gt = "1970/01/01 00:00:00",
-                                }
-                            }
-                        },
-                        sterm
-                    }
-                }
-            },
-            sort = {
-                {
-                    date = {
-                        order = "asc"
-                    }
-                }  
-            },
-            size = 1
-        }
-        firstYear = tonumber(os.date("%Y", doc.hits.hits[1] and doc.hits.hits[1]._source.epoch or os.time()))
-        r:ivm_set(FIRSTYEAR_KEY, firstYear)
-    end
-    
-    -- Get years active
     local LASTYEAR_KEY = "lastYear:" .. NOWISH .. ":" .. get.list .. "@" .. get.domain
+    local firstYear = r:ivm_get(FIRSTYEAR_KEY)
     local lastYear = r:ivm_get(LASTYEAR_KEY)
-    if (not lastYear or lastYear == "")  and not statsOnly then
+    if (not firstYear or firstYear == "" or not lastYear or lastYear == "") and not statsOnly then
         local doc = elastic.raw {
+            size = 0,
             query = {
                 bool = {
                     must = {
@@ -494,21 +465,25 @@ function handle(r)
                     }
                 }
             },
-            
-            sort = {
-                {
-                    epoch = {
-                        order = "desc"
-                    }
-                }  
-            },
-            size = 1
+            aggs = {
+                first = {
+                   min =  {
+                      field = "date"
+                  }
+              },
+              last = {
+                   max = {
+                    field = "date"
+                  }
+                }
+            }
         }
-        lastYear = tonumber(os.date("%Y", doc.hits.hits[1] and doc.hits.hits[1]._source.epoch or os.time()))
+        firstYear = tonumber(os.date("%Y", doc.aggregations.first.value/1000))
+        r:ivm_set(FIRSTYEAR_KEY, firstYear)
+        lastYear = tonumber(os.date("%Y", doc.aggregations.last.value/1000))
         r:ivm_set(LASTYEAR_KEY, lastYear)
     end
     
-    
     -- Debug time point 6
     table.insert(t, r:clock() - tnow)
     tnow = r:clock()


[2/2] incubator-ponymail git commit: stats.lua can fail when creating top10 senders

Posted by se...@apache.org.
stats.lua can fail when creating top10 senders

This fixes #283

Project: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/commit/68ea3726
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/tree/68ea3726
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/diff/68ea3726

Branch: refs/heads/master
Commit: 68ea3726e90523f32e8648db297063b020339c8c
Parents: 36e6d59
Author: Sebb <se...@apache.org>
Authored: Sun Dec 11 02:18:24 2016 +0000
Committer: Sebb <se...@apache.org>
Committed: Sun Dec 11 02:18:24 2016 +0000

----------------------------------------------------------------------
 CHANGELOG.md       | 1 +
 site/api/stats.lua | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/68ea3726/CHANGELOG.md
----------------------------------------------------------------------
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 372f60b..4c714eb 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -54,6 +54,7 @@
 - search strings not properly quoted. (#76)
 - pminfo.lua creates top100 sender information but it's not used (#282)
 - stats.lua could use single aggregate query to get first and last years (#276)
+- stats.lua can fail when creating top10 senders (#283)
 
 ## CHANGES in 0.9b:
 

http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/68ea3726/site/api/stats.lua
----------------------------------------------------------------------
diff --git a/site/api/stats.lua b/site/api/stats.lua
index 6fa0da3..e8cf3e1 100644
--- a/site/api/stats.lua
+++ b/site/api/stats.lua
@@ -365,7 +365,7 @@ function handle(r)
                 eml = "unknown"
             end
             local gravatar = r:md5(eml:lower())
-            local name = y.key:match("([^<]+)%s*<.->") or y.key:match("%S+@%S+")
+            local name = y.key:match("([^<]+)%s*<.->") or y.key:match("%S+@%S+") or "unknown"
             name = name:gsub("\"", "")
             table.insert(top10, {
                 id = y.key,