ponymail-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject incubator-ponymail git commit: Cache keys should be constants
Date Wed, 07 Dec 2016 12:25:05 GMT
Repository: incubator-ponymail
Updated Branches:
  refs/heads/master 94d441373 -> 4b8ebd4b1


Cache keys should be constants

This fixes #275

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

Branch: refs/heads/master
Commit: 4b8ebd4b188df1f2ed1e9bfa03419d87bdcc8116
Parents: 94d4413
Author: Sebb <sebb@apache.org>
Authored: Wed Dec 7 12:24:46 2016 +0000
Committer: Sebb <sebb@apache.org>
Committed: Wed Dec 7 12:24:46 2016 +0000

----------------------------------------------------------------------
 site/api/lib/aaa.lua     |  9 +++++----
 site/api/preferences.lua | 12 +++++++-----
 site/api/stats.lua       | 12 +++++++-----
 3 files changed, 19 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/4b8ebd4b/site/api/lib/aaa.lua
----------------------------------------------------------------------
diff --git a/site/api/lib/aaa.lua b/site/api/lib/aaa.lua
index e3509cd..0188137 100644
--- a/site/api/lib/aaa.lua
+++ b/site/api/lib/aaa.lua
@@ -33,8 +33,9 @@ end
 function isMember(r, uid)
     
     -- First, check the 30 minute cache
-    local nowish = math.floor(os.time() / 1800)
-    local t = r:ivm_get("isMember_" .. nowish .. "_" .. uid)
+    local NOWISH = math.floor(os.time() / 1800)
+    local MEMBER_KEY = "isMember_" .. NOWISH .. "_" .. uid
+    local t = r:ivm_get(MEMBER_KEY)
     
     -- If cached, then just return the value
     if t then
@@ -48,14 +49,14 @@ function isMember(r, uid)
             -- Found it?
             if match == uid then
                 -- Set cache
-                r:ivm_set("isMember_" .. nowish .. "_" .. uid, "1")
+                r:ivm_set(MEMBER_KEY, "1")
                 return true
             end
         end
     end
     
     -- Set cache
-    r:ivm_set("isMember_" .. nowish .. "_" .. uid, "0")
+    r:ivm_set(MEMBER_KEY, "0")
     return false
 end
 

http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/4b8ebd4b/site/api/preferences.lua
----------------------------------------------------------------------
diff --git a/site/api/preferences.lua b/site/api/preferences.lua
index d80cedd..59f1e19 100644
--- a/site/api/preferences.lua
+++ b/site/api/preferences.lua
@@ -211,8 +211,9 @@ Pony Mail - Email for Ponies and People.
     
     -- Get lists (cached if possible)
     local lists = {}
-    local nowish = math.floor(os.time() / 600)
-    local cache = r:ivm_get("pm_lists_cache_" ..r.hostname .."-" .. nowish)
+    local NOWISH = math.floor(os.time() / 600)
+    local PM_LISTS_KEY = "pm_lists_cache_" .. r.hostname .. "-" .. NOWISH
+    local cache = r:ivm_get(PM_LISTS_KEY)
     if cache then
         lists = JSON.decode(cache)
     else
@@ -264,7 +265,7 @@ Pony Mail - Email for Ponies and People.
         end
         
         -- save temporary list in cache
-        r:ivm_set("pm_lists_cache_" ..r.hostname .."-" .. nowish, JSON.encode(lists))
+        r:ivm_set(PM_LISTS_KEY, JSON.encode(lists))
         
         -- hide private lists?
         -- this invalidates any cache there is and forces a check for
@@ -272,7 +273,8 @@ Pony Mail - Email for Ponies and People.
         -- does not have access, the list is hidden
     end
     if config.hidePrivate then
-        local cache = r:ivm_get("pm_lists_cache_private_" ..r.hostname .."-" .. nowish)
+        local PM_LISTS_PRIVATE_KEY = "pm_lists_cache_private_" .. r.hostname .. "-" .. NOWISH
+        local cache = r:ivm_get(PM_LISTS_PRIVATE_KEY)
         local pdoc
         if cache then
             pdoc = JSON.decode(cache)
@@ -305,7 +307,7 @@ Pony Mail - Email for Ponies and People.
                     }
                 }
             }
-            r:ivm_set("pm_lists_cache_private_" ..r.hostname .."-" .. nowish, JSON.encode(pdoc))
+            r:ivm_set(PM_LISTS_PRIVATE_KEY, JSON.encode(pdoc))
         end
         
         local rights = {}

http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/4b8ebd4b/site/api/stats.lua
----------------------------------------------------------------------
diff --git a/site/api/stats.lua b/site/api/stats.lua
index 2fbaaa7..a975d52 100644
--- a/site/api/stats.lua
+++ b/site/api/stats.lua
@@ -434,8 +434,9 @@ function handle(r)
     tnow = r:clock()
     
     -- Get years active
-    local nowish = math.floor(os.time()/600)
-    local firstYear = r:ivm_get("firstYear:" .. nowish .. ":" ..get.list .. "@" .. get.domain)
+    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 = {
@@ -462,11 +463,12 @@ function handle(r)
             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:" .. nowish .. ":" .. get.list .. "@" .. get.domain, firstYear)
+        r:ivm_set(FIRSTYEAR_KEY, firstYear)
     end
     
     -- Get years active
-    local lastYear = r:ivm_get("lastYear:" .. nowish .. ":" ..get.list .. "@" .. get.domain)
+    local LASTYEAR_KEY = "lastYear:" .. NOWISH .. ":" .. get.list .. "@" .. get.domain
+    local lastYear = r:ivm_get(LASTYEAR_KEY)
     if (not lastYear or lastYear == "")  and not statsOnly then
         local doc = elastic.raw {
             query = {
@@ -494,7 +496,7 @@ function handle(r)
             size = 1
         }
         lastYear = tonumber(os.date("%Y", doc.hits.hits[1] and doc.hits.hits[1]._source.epoch
or os.time()))
-        r:ivm_set("lastYear:"  .. nowish .. ":" ..get.list .. "@" .. get.domain, lastYear)
+        r:ivm_set(LASTYEAR_KEY, lastYear)
     end
     
     


Mime
View raw message