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/04/20 10:33:28 UTC

incubator-ponymail git commit: Enh: make debug info optional

Repository: incubator-ponymail
Updated Branches:
  refs/heads/master 532af0b72 -> 491e3809d


Enh: make debug info optional

This fixes #369

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

Branch: refs/heads/master
Commit: 491e3809ddfb53f1cd07a17ab52f84ec6ca989d5
Parents: 532af0b
Author: Sebb <se...@apache.org>
Authored: Thu Apr 20 11:33:24 2017 +0100
Committer: Sebb <se...@apache.org>
Committed: Thu Apr 20 11:33:24 2017 +0100

----------------------------------------------------------------------
 CHANGELOG.md             |  1 +
 site/api/pminfo.lua      | 58 ++++++++++++++++++++++++-------------
 site/api/preferences.lua |  5 ++--
 site/api/stats.lua       | 66 ++++++++++++++++++++++++++++---------------
 site/api/thread.lua      |  5 ++--
 5 files changed, 89 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/491e3809/CHANGELOG.md
----------------------------------------------------------------------
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 39fdda5..c8514b1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -145,6 +145,7 @@
 - Bug: source.lua does not specify the charset (#367)
 - Bug: archiver stores attachment binary data types with embedded newlines (#262)
 - Bug: may corrupt 8bit message source if it is not encoded in UTF-8 (#366)
+- Enh: make debug info optional (#369)
 
 ## CHANGES in 0.9b:
 

http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/491e3809/site/api/pminfo.lua
----------------------------------------------------------------------
diff --git a/site/api/pminfo.lua b/site/api/pminfo.lua
index 8a927d5..1d5615f 100644
--- a/site/api/pminfo.lua
+++ b/site/api/pminfo.lua
@@ -20,12 +20,15 @@
 local JSON = require 'cjson'
 local elastic = require 'lib/elastic'
 local cross = require 'lib/cross'
+local config = require 'lib/config'
 
 function handle(r)
     cross.contentType(r, "application/json")
+    local DEBUG = config.debug or false
+    -- Cannot define local variables within a conditional block
     local t = {}
-    local now = r:clock()
-    local tnow = now
+    local START = DEBUG and r:clock() or nil
+    local tnow = START
     local DD = 14
     
     local NOWISH = math.floor(os.time() / 1800)
@@ -38,9 +41,11 @@ function handle(r)
     end
 
     -- Debug time point 1
-    table.insert(t, r:clock() - tnow)
-    tnow = r:clock()
-    
+    if DEBUG then
+      table.insert(t, r:clock() - tnow)
+      tnow = r:clock()
+    end
+
     local daterange = {gt = "now-"..DD.."d", lt = "now+1d" }
     
     -- common query
@@ -92,8 +97,10 @@ function handle(r)
     local no_senders = doc.aggregations.cards.value
     
     -- Debug time point 2
-    table.insert(t, r:clock() - tnow)
-    tnow = r:clock()
+    if DEBUG then
+      table.insert(t, r:clock() - tnow)
+      tnow = r:clock()
+    end
     
     local activity = {}
     
@@ -102,12 +109,14 @@ function handle(r)
     end
         
     -- Debug time point 3
-    table.insert(t, r:clock() - tnow)
-    tnow = r:clock()
-        
+    if DEBUG then
+      table.insert(t, r:clock() - tnow)
+      tnow = r:clock()
+
     -- Debug time point 4
-    table.insert(t, r:clock() - tnow)
-    tnow = r:clock()
+      table.insert(t, r:clock() - tnow)
+      tnow = r:clock()
+    end
     
     
     -- Get threads
@@ -145,8 +154,10 @@ function handle(r)
     end
     
     -- Debug time point 5
-    table.insert(t, r:clock() - tnow)
-    tnow = r:clock()
+    if DEBUG then
+      table.insert(t, r:clock() - tnow)
+      tnow = r:clock()
+    end
     
     for k = #hits, 1, -1 do
         local v = hits[k]
@@ -204,8 +215,10 @@ function handle(r)
     end
     
     -- Debug time point 6
-    table.insert(t, r:clock() - tnow)
-    tnow = r:clock()
+    if DEBUG then
+      table.insert(t, r:clock() - tnow)
+      tnow = r:clock()
+    end
     
     JSON.encode_max_depth(500)
     local listdata = {}
@@ -214,14 +227,19 @@ function handle(r)
     listdata.hits = total_docs
     listdata.participants = no_senders
     listdata.no_active_lists = nal
-    listdata.took = r:clock() - now
+    if DEBUG then
+      listdata.took = r:clock() - START
+    end
+
     listdata.activity = activity
     
     -- Debug time point 7
-    table.insert(t, r:clock() - tnow)
-    tnow = r:clock()
+    if DEBUG then
+      table.insert(t, r:clock() - tnow)
+      tnow = r:clock()
+      listdata.debug = t
+    end
     
-    listdata.debug = t
     local output = JSON.encode(listdata)
     r:ivm_set(PMINFO_CACHE_KEY, output)
     r:puts(output)

http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/491e3809/site/api/preferences.lua
----------------------------------------------------------------------
diff --git a/site/api/preferences.lua b/site/api/preferences.lua
index e4da480..384cf1e 100644
--- a/site/api/preferences.lua
+++ b/site/api/preferences.lua
@@ -62,7 +62,8 @@ Parameters: (cookie required)
 ]]--
 function handle(r)
     cross.contentType(r, "application/json")
-    local now = r:clock()
+    local DEBUG = config.debug or false
+    local START = DEBUG and r:clock() or nil
     local get = r:parseargs()
     
     
@@ -403,7 +404,7 @@ Pony Mail - Email for Ponies and People.
             notifications = notifications,
             alternates = alts
         },
-        took = r:clock() - now
+        took = DEBUG and (r:clock() - START) or nil
     })
     
     return cross.OK

http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/491e3809/site/api/stats.lua
----------------------------------------------------------------------
diff --git a/site/api/stats.lua b/site/api/stats.lua
index d8e4801..2d0398d 100644
--- a/site/api/stats.lua
+++ b/site/api/stats.lua
@@ -61,9 +61,10 @@ end
 
 function handle(r)
     cross.contentType(r, "application/json")
+    local DEBUG = config.debug or false
     local t = {}
-    local now = r:clock()
-    local tnow = now
+    local START = DEBUG and r:clock() or nil
+    local tnow = START
     local get = r:parseargs()
     -- statsOnly: Whether to only send statistical info (for n-grams etc), and not the
     -- thread struct and message bodies
@@ -162,8 +163,10 @@ function handle(r)
     end
     
     -- Debug time point 1
-    table.insert(t, r:clock() - tnow)
-    tnow = r:clock()
+    if DEBUG then
+      table.insert(t, r:clock() - tnow)
+      tnow = r:clock()
+    end
     
     local daterange = {gt = "now-1M", lte = "now+1d" }
     -- Param: dfrom=.*ddd (days ago to start)
@@ -310,7 +313,7 @@ function handle(r)
         if #doc.hits.hits == 0 then
             r:puts(JSON.encode{
                 changed = false,
-                took = r:clock() - tnow
+                took = r:clock() - START
             })
             return cross.OK
         end
@@ -319,8 +322,11 @@ function handle(r)
     -- Debug time point 3 was for slow_count
     
     -- Debug time point 4
-    table.insert(t, r:clock() - tnow)
-    tnow = r:clock()
+    if DEBUG then
+      table.insert(t, r:clock() - tnow)
+      tnow = r:clock()
+    end
+
     local cloud = nil
     if config.wordcloud and not statsOnly then
         cloud = {}
@@ -374,8 +380,10 @@ function handle(r)
         end
     end
     -- Debug time point 5
-    table.insert(t, r:clock() - tnow)
-    tnow = r:clock()
+    if DEBUG then
+      table.insert(t, r:clock() - tnow)
+      tnow = r:clock()
+    end
     
     -- Get years active
     local NOWISH = math.floor(os.time()/600)
@@ -489,8 +497,10 @@ function handle(r)
     datespan.lastMonth = tonumber(os.date("%m", last))
     
     -- Debug time point 6
-    table.insert(t, r:clock() - tnow)
-    tnow = r:clock()
+    if DEBUG then
+      table.insert(t, r:clock() - tnow)
+      tnow = r:clock()
+    end
 
     -- Get threads
     local threads = {}
@@ -562,8 +572,10 @@ function handle(r)
     local h = 0
     
     -- Debug time point 7
-    table.insert(t, r:clock() - tnow)
-    tnow = r:clock()
+    if DEBUG then
+      table.insert(t, r:clock() - tnow)
+      tnow = r:clock()
+    end
     
     
     for k = #dhh, 1, -1 do
@@ -699,13 +711,19 @@ function handle(r)
     end
     
     -- Debug time point 8
-    table.insert(t, r:clock() - tnow)
-    tnow = r:clock()
+    if DEBUG then
+      table.insert(t, r:clock() - tnow)
+      tnow = r:clock()
+    end
+
     sortEmail(threads)
     
     -- Debug time point 9
-    table.insert(t, r:clock() - tnow)
-    tnow = r:clock()
+    if DEBUG then
+      table.insert(t, r:clock() - tnow)
+      tnow = r:clock()
+    end
+
     if JSON.encode_max_depth then
         JSON.encode_max_depth(500)
     end
@@ -725,16 +743,20 @@ function handle(r)
     listdata.searchlist = listraw
     listdata.participants = top10
     listdata.cloud = cloud
-    listdata.took = r:clock() - now
+    if DEBUG then
+      listdata.took = r:clock() - START
+    end
     listdata.numparts = allparts
     listdata.unixtime = os.time()
     
     -- Debug time point 9
-    table.insert(t, r:clock() - tnow)
-    tnow = r:clock()
-    
-    listdata.debug = t
+    if DEBUG then
+      table.insert(t, r:clock() - tnow)
+      tnow = r:clock()
     
+      listdata.debug = t
+    end    
+
     r:puts(JSON.encode(listdata))
     
     return cross.OK

http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/491e3809/site/api/thread.lua
----------------------------------------------------------------------
diff --git a/site/api/thread.lua b/site/api/thread.lua
index 4065c65..b32db2b 100644
--- a/site/api/thread.lua
+++ b/site/api/thread.lua
@@ -70,7 +70,8 @@ end
 
 function handle(r)
     cross.contentType(r, "application/json")
-    local now = r:clock()
+    local DEBUG = config.debug or false
+    local START = DEBUG and r:clock() or nil
     local get = r:parseargs()
     -- get the parameter (if any) and tidy it up
     local eid = (get.id or ""):gsub("\"", "")
@@ -110,7 +111,7 @@ function handle(r)
             doc.id = doc.request_id
             --doc.body = nil
             r:puts(JSON.encode({
-                took = r:clock() - now,
+                took = DEBUG and (r:clock() - START) or nil,
                 thread = doc,
                 emails = emls_thrd,
             }))