You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ponymail.apache.org by hu...@apache.org on 2016/09/04 07:23:39 UTC
[07/11] incubator-ponymail git commit: implement a caching feature
for list data
implement a caching feature for list data
Project: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/commit/cb209e2b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/tree/cb209e2b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/diff/cb209e2b
Branch: refs/heads/coffee-and-cake
Commit: cb209e2b3a56641f50059e46fe88ad56289c39bc
Parents: 91a25ee
Author: Daniel Gruno <hu...@apache.org>
Authored: Sun Sep 4 09:21:41 2016 +0200
Committer: Daniel Gruno <hu...@apache.org>
Committed: Sun Sep 4 09:21:41 2016 +0200
----------------------------------------------------------------------
site/js/coffee/listview.coffee | 38 +++++++++++++++++++++++++++++++------
1 file changed, 32 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/cb209e2b/site/js/coffee/listview.coffee
----------------------------------------------------------------------
diff --git a/site/js/coffee/listview.coffee b/site/js/coffee/listview.coffee
index 8f97c79..cd9643d 100644
--- a/site/js/coffee/listview.coffee
+++ b/site/js/coffee/listview.coffee
@@ -28,6 +28,7 @@ parseURL = () ->
ponymail_list = list
ponymail_month = month||""
ponymail_query = query||""
+ [ponymail_listname, ponymail_domain] = list.split("@")
@@ -90,15 +91,40 @@ listView = (hash, reParse) ->
pargs = "d=30"
if ponymail_month and ponymail_month.length > 0
pargs = "s=#{ponymail_month}&e=#{ponymail_month}"
- r = new HTTPRequest(
- "api/stats.lua?list=#{list}&domain=#{domain}&#{pargs}",
- {
- callback: renderListView
- }
- )
+
+ ### If we already fetched this URL once, only do an update check ###
+ if ponymail_list_json[newhref] and ponymail_list_json[newhref].unixtime > 0
+ since = ponymail_list_json[newhref].unixtime
+ r = new HTTPRequest(
+ "api/stats.lua?list=#{list}&domain=#{domain}&#{pargs}&since=#{since}",
+ {
+ callback: renderListView
+ state: {
+ href: newhref
+ }
+ }
+ )
+ else
+ r = new HTTPRequest(
+ "api/stats.lua?list=#{list}&domain=#{domain}&#{pargs}",
+ {
+ callback: renderListView
+ state: {
+ href: newhref
+ }
+ }
+ )
renderListView = (json, state) ->
+ ### If this is a cache check callback, and nothing has changed, use the old JSON ###
+ if state and state.href and json.changed is false
+ json = ponymail_list_json[state.href]
+ json.cached = true
+ else if state and state.href
+ ### Save JSON in cache if new ###
+ ponymail_list_json[state.href] = json
+
### Start by adding the calendar ###
if json.firstYear and json.lastYear
cal = new Calendar(json.firstYear, json.lastYear, ponymail_month)