Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id E172D200C02 for ; Fri, 6 Jan 2017 00:48:46 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id DCCA0160B45; Thu, 5 Jan 2017 23:48:46 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 0AF42160B33 for ; Fri, 6 Jan 2017 00:48:45 +0100 (CET) Received: (qmail 94916 invoked by uid 500); 5 Jan 2017 23:48:45 -0000 Mailing-List: contact commits-help@ponymail.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ponymail.incubator.apache.org Delivered-To: mailing list commits@ponymail.incubator.apache.org Received: (qmail 94903 invoked by uid 99); 5 Jan 2017 23:48:45 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 Jan 2017 23:48:45 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id C1716C1434 for ; Thu, 5 Jan 2017 23:48:44 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -6.219 X-Spam-Level: X-Spam-Status: No, score=-6.219 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-2.999] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id QSYnDrhfG3Qg for ; Thu, 5 Jan 2017 23:48:43 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with SMTP id DCCE45F30C for ; Thu, 5 Jan 2017 23:48:42 +0000 (UTC) Received: (qmail 94886 invoked by uid 99); 5 Jan 2017 23:48:42 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 Jan 2017 23:48:42 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 0E2FCDF9E6; Thu, 5 Jan 2017 23:48:42 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sebb@apache.org To: commits@ponymail.incubator.apache.org Message-Id: <319198b1d2824db9b4c3145a48136282@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: incubator-ponymail git commit: Rework the list count handling Date: Thu, 5 Jan 2017 23:48:42 +0000 (UTC) archived-at: Thu, 05 Jan 2017 23:48:47 -0000 Repository: incubator-ponymail Updated Branches: refs/heads/master db233b3bd -> 36b138444 Rework the list count handling Squash the returned data counts before caching Calculate the user access from the data counts Project: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/commit/36b13844 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/tree/36b13844 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/diff/36b13844 Branch: refs/heads/master Commit: 36b13844477c3c5ce69aafdbfeb1d128acc8b991 Parents: db233b3 Author: Sebb Authored: Thu Jan 5 23:48:08 2017 +0000 Committer: Sebb Committed: Thu Jan 5 23:48:08 2017 +0000 ---------------------------------------------------------------------- site/api/preferences.lua | 58 ++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 25 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/36b13844/site/api/preferences.lua ---------------------------------------------------------------------- diff --git a/site/api/preferences.lua b/site/api/preferences.lua index 16a9297..353bd34 100644 --- a/site/api/preferences.lua +++ b/site/api/preferences.lua @@ -275,13 +275,13 @@ Pony Mail - Email for Ponies and People. end end - -- Get lists (cached if possible) - local lists = {} + -- Get list counts (cached if possible) local NOWISH = math.floor(os.time() / 600) - local PM_LISTS_KEY = "pm_lists_cache_" .. r.hostname .. "-" .. NOWISH + local PM_LISTS_KEY = "pm_lists_counts_" .. r.hostname .. "-" .. NOWISH local cache = r:ivm_get(PM_LISTS_KEY) + local listcounts = {} -- summary of aggregated data for cache if cache then - lists = JSON.decode(cache) + listcounts = JSON.decode(cache) else -- aggregate the documents by listname, privacy flag, recent docs @@ -313,33 +313,41 @@ Pony Mail - Email for Ponies and People. } } } - -- Now process the docs that are visible to the user + -- squash the output for caching (it's quite verbose otherwise) for _, entry in pairs (alldocs.aggregations.listnames.buckets) do local listname = entry.key:lower() - local _, list, domain = aaa.parseLid(listname) - -- TODO is it necessary to check the lengths? - if list and domain and #list > 0 and #domain > 3 then - -- check public and private (only one may be present) - for _, privacy in pairs(entry.privacy.buckets) do - local isPublic = privacy.key_as_string == 'false' - -- do the user have access? - if isPublic or aaa.canAccessList(r, listname, account) then - -- there is only a single recent bucket; access it directly - local recent_count = privacy.recent.buckets[1].doc_count - -- create the domain entry if necessary - lists[domain] = lists[domain] or {} - -- check if we have a list entry yet - if lists[domain][list] then - lists[domain][list] = lists[domain][list] + recent_count - else - lists[domain][list] = recent_count -- init the entry - end + listcounts[listname] = {} + -- the same list may have both private and public docs + for _, privacy in pairs(entry.privacy.buckets) do + listcounts[listname][privacy.key_as_string] = privacy.recent.buckets[1].doc_count + end + end + -- save the squashed counts in cache + r:ivm_set(PM_LISTS_KEY, JSON.encode(listcounts)) + end + + -- Now count the docs and lists that are visible to the current user + local lists = {} + for listname, entry in pairs(listcounts) do + local _, list, domain = aaa.parseLid(listname) + -- TODO is it necessary to check the lengths? + if list and domain and #list > 0 and #domain > 3 then + -- there may be both private and public docs in the list + for privacy, recent_count in pairs(entry) do + local isPublic = privacy == 'false' + -- does the user have access to this list? + if isPublic or aaa.canAccessList(r, listname, account) then + -- create the domain entry if necessary + lists[domain] = lists[domain] or {} + -- check if we have a list entry yet + if lists[domain][list] then + lists[domain][list] = lists[domain][list] + recent_count + else + lists[domain][list] = recent_count -- init the entry end end end end - -- save temporary list in cache - r:ivm_set(PM_LISTS_KEY, JSON.encode(lists)) end -- do we need to remove junk?