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 2017/01/23 23:06:32 UTC
incubator-ponymail git commit: stats.lua first/last dates don't
always agree with visible mails
Repository: incubator-ponymail
Updated Branches:
refs/heads/master 4cd8921f9 -> 0ee200819
stats.lua first/last dates don't always agree with visible mails
This fixes #350
Project: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/commit/0ee20081
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/tree/0ee20081
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/diff/0ee20081
Branch: refs/heads/master
Commit: 0ee20081910def09ee51e71100e9cd82f3e17cf2
Parents: 4cd8921
Author: Sebb <se...@apache.org>
Authored: Mon Jan 23 23:06:24 2017 +0000
Committer: Sebb <se...@apache.org>
Committed: Mon Jan 23 23:06:24 2017 +0000
----------------------------------------------------------------------
CHANGELOG.md | 1 +
site/api/stats.lua | 97 +++++++++++++++++++++++++++++++++++++++----------
2 files changed, 79 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/0ee20081/CHANGELOG.md
----------------------------------------------------------------------
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f63d25d..473bbf6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -130,6 +130,7 @@
- list name not normalised when imported (#253)
- GUI ignores date span in list.html URI if query is blank (#346)
- search phrase dropped from list.html URI if date span is yyyy-mm (#347)
+- stats.lua first/last dates don't always agree with visible mails (#350)
## CHANGES in 0.9b:
http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/0ee20081/site/api/stats.lua
----------------------------------------------------------------------
diff --git a/site/api/stats.lua b/site/api/stats.lua
index bcadf11..647d289 100644
--- a/site/api/stats.lua
+++ b/site/api/stats.lua
@@ -382,7 +382,7 @@ function handle(r)
local DATESPAN_KEY = "dateSpan:" .. NOWISH .. ":" .. get.list .. "@" .. get.domain
local datespan = JSON.decode(r:ivm_get(DATESPAN_KEY) or "{}")
- if not (datespan.firstYear and datespan.lastYear and datespan.firstMonth and datespan.lastMonth) then
+ if not (datespan.pubfirst and datespan.publast) then
local doc = elastic.raw {
size = 0,
query = {
@@ -400,31 +400,90 @@ function handle(r)
}
},
aggs = {
- first = {
- min = {
- field = "epoch"
- }
- },
- last = {
- max = {
- field = "epoch"
- }
+ lists = {
+ terms = {
+ field = "list_raw",
+ size = 500000
+ },
+ aggs = {
+ private = {
+ terms = {
+ field = "private",
+ size = 2
+ },
+ aggs = {
+ first = {
+ min = {
+ field = "epoch"
+ }
+ },
+ last = {
+ max = {
+ field = "epoch"
+ }
+ }
+ }
+ }
+ }
}
}
}
datespan = {}
- local first = doc.aggregations.first.value
- if first == JSON.null then first = os.time() else first = first end
- datespan.firstYear = tonumber(os.date("%Y", first))
- datespan.firstMonth = tonumber(os.date("%m", first))
+ local NOW = os.time()
+ datespan.pubfirst = NOW -- earliest time must be less than this
+ datespan.publast = 0
+ -- find public min and max (buckets will be empty if there are no matching lists)
+ for _, list in pairs(doc.aggregations.lists.buckets) do
+ for _, private in pairs(list.private.buckets) do
+ if private.key_as_string == "false" then
+ if private.last.value > datespan.publast then datespan.publast = private.last.value end
+ if private.first.value < datespan.pubfirst then datespan.pubfirst = private.first.value end
+ end
+ end
+ end
+ if datespan.publast == 0 then datespan.publast = NOW end -- no value found
- local last = doc.aggregations.last.value
- if last == JSON.null then last = os.time() else last = last end
- datespan.lastYear = tonumber(os.date("%Y", last))
- datespan.lastMonth = tonumber(os.date("%m", last))
+ -- find private min and max and store them if they could change the public ones
+ -- store the list entries under the 'private' key to make them easier to process
+ for _, list in pairs(doc.aggregations.lists.buckets) do
+ for _, private in pairs(list.private.buckets) do
+ if private.key_as_string == "true" then
+ local prvlast = private.last.value
+ if prvlast > datespan.publast then
+ datespan.private = datespan.private or {}
+ datespan.private[list.key] = datespan.private[list.key] or {}
+ datespan.private[list.key].last = prvlast
+ end
+ local prvfirst = private.first.value
+ if prvfirst < datespan.pubfirst then
+ datespan.private = datespan.private or {}
+ datespan.private[list.key] = datespan.private[list.key] or {}
+ datespan.private[list.key].first = prvfirst
+ end
+ end
+ end
+ end
+
+ r:ivm_set(DATESPAN_KEY, JSON.encode(datespan))
+ end
- r:ivm_set(DATESPAN_KEY, JSON.encode(datespan))
+ -- process the raw list data:
+ -- get the first and last dates, adjusting as necessary to allow for private lists
+ local first = datespan.pubfirst
+ local last = datespan.publast
+ for lid, prvdates in pairs(datespan.private or {}) do
+ if aaa.canAccessList(r, lid, account) then
+ if prvdates.first and prvdates.first < first then first = prvdates.first end
+ if prvdates.last and prvdates.last > last then last = prvdates.last end
+ end
end
+
+ -- extract years and months for response
+ datespan.firstYear = tonumber(os.date("%Y", first))
+ datespan.firstMonth = tonumber(os.date("%m", first))
+
+ datespan.lastYear = tonumber(os.date("%Y", last))
+ datespan.lastMonth = tonumber(os.date("%m", last))
-- Debug time point 6
table.insert(t, r:clock() - tnow)