This is an automated email from the ASF dual-hosted git repository. rubys pushed a commit to branch master in repository https://git-dual.apache.org/repos/asf/whimsy.git
The following commit(s) were added to refs/heads/master by this push: new dad4c18 locally cache a few results dad4c18 is described below commit dad4c184b5a1b6f522f139674a19daea1c53d8f2 Author: Sam Ruby <ru...@intertwingly.net> AuthorDate: Tue Apr 19 07:41:56 2016 -0400 locally cache a few results --- www/board/agenda/views/app.js.rb | 1 + www/board/agenda/views/models/comments.js.rb | 4 +-- www/board/agenda/views/models/events.js.rb | 26 +++++++++++------- www/board/agenda/views/models/jira.js.rb | 4 +-- www/board/agenda/views/models/jsonstorage.js.rb | 35 +++++++++++++++++++++++++ www/board/agenda/views/models/posted.js.rb | 3 ++- 6 files changed, 59 insertions(+), 14 deletions(-) diff --git a/www/board/agenda/views/app.js.rb b/www/board/agenda/views/app.js.rb index 3dcf14a..eaf9905 100644 --- a/www/board/agenda/views/app.js.rb +++ b/www/board/agenda/views/app.js.rb @@ -59,3 +59,4 @@ require_relative 'models/jira' require_relative 'models/pending' require_relative 'models/posted' require_relative 'models/comments' +require_relative 'models/jsonstorage' diff --git a/www/board/agenda/views/models/comments.js.rb b/www/board/agenda/views/models/comments.js.rb index 0b18c8a..f225bf5 100644 --- a/www/board/agenda/views/models/comments.js.rb +++ b/www/board/agenda/views/models/comments.js.rb @@ -10,9 +10,9 @@ class HistoricalComments if @@comments return @@comments[title] elsif defined? XMLHttpRequest - @@comments = {} + @@comments = JSONStorage.get('comments') || {} fetch('historical-comments', :json) do |comments| - @@comments = comments + @@comments = JSONStorage.put('comments', comments) if comments end end end diff --git a/www/board/agenda/views/models/events.js.rb b/www/board/agenda/views/models/events.js.rb index 69efc4d..351b8ae 100644 --- a/www/board/agenda/views/models/events.js.rb +++ b/www/board/agenda/views/models/events.js.rb @@ -40,15 +40,7 @@ class Events end def self.monitor() - # determine localStorage variable prefix based on url up to the date - base = document.getElementsByTagName("base")[0].href - origin = location.origin - if not origin # compatibility: http://s.apache.org/X2L - origin = window.location.protocol + "//" + window.location.hostname + - (window.location.port ? ':' + window.location.port : '') - end - @@prefix = base[origin.length..-1].sub(/\/\d{4}-\d\d-\d\d\/.*/, ''). - gsub(/^\W+|\W+$/, '').gsub(/\W+/, '_') || location.port + @@prefix = JSONStorage.prefix # pick something unique to identify this tab/window @@timestamp = Date.new().getTime() + Math.random() @@ -153,4 +145,20 @@ class Events return if !navigator.userAgent or navigator.userAgent.include? 'PhantomJS' console.log message end + + # make the computed prefix available + def self.prefix + return @@prefix if @@prefix + + # determine localStorage variable prefix based on url up to the date + base = document.getElementsByTagName("base")[0].href + origin = location.origin + if not origin # compatibility: http://s.apache.org/X2L + origin = window.location.protocol + "//" + window.location.hostname + + (window.location.port ? ':' + window.location.port : '') + end + + @@prefix = base[origin.length..-1].sub(/\/\d{4}-\d\d-\d\d\/.*/, ''). + gsub(/^\W+|\W+$/, '').gsub(/\W+/, '_') || location.port + end end diff --git a/www/board/agenda/views/models/jira.js.rb b/www/board/agenda/views/models/jira.js.rb index 8fff3a9..073d22d 100644 --- a/www/board/agenda/views/models/jira.js.rb +++ b/www/board/agenda/views/models/jira.js.rb @@ -9,9 +9,9 @@ class JIRA if @@list return @@list.include? name elsif defined? XMLHttpRequest - @@list = [] + @@list = JSONStorage.get('jira') || [] fetch('jira', :json) do |list| - @@list = list + @@list = JSONStorage.put('jira', list) if list end end end diff --git a/www/board/agenda/views/models/jsonstorage.js.rb b/www/board/agenda/views/models/jsonstorage.js.rb new file mode 100644 index 0000000..8ef5b56 --- /dev/null +++ b/www/board/agenda/views/models/jsonstorage.js.rb @@ -0,0 +1,35 @@ +# +# Simplify access to localStorage for JSON objects +# + +class JSONStorage + # determine localStorage variable prefix based on url up to the date + def self.prefix + return @@prefix if @@prefix + + base = document.getElementsByTagName("base")[0].href + origin = location.origin + if not origin # compatibility: http://s.apache.org/X2L + origin = window.location.protocol + "//" + window.location.hostname + + (window.location.port ? ':' + window.location.port : '') + end + + @@prefix = base[origin.length..-1].sub(/\/\d{4}-\d\d-\d\d\/.*/, ''). + gsub(/^\W+|\W+$/, '').gsub(/\W+/, '_') || location.port + end + + # store an item, converting it to JSON + def self.put(name, value) + name = JSONStorage.prefix + '-' + name + localStorage.setItem(name, JSON.stringify(value)) + return value + end + + # retrieve an item, converting it back to an object + def self.get(name) + if defined? localStorage + name = JSONStorage.prefix + '-' + name + return JSON.parse(localStorage.getItem(name) || 'null') + end + end +end diff --git a/www/board/agenda/views/models/posted.js.rb b/www/board/agenda/views/models/posted.js.rb index 4acb75c..51f3c65 100644 --- a/www/board/agenda/views/models/posted.js.rb +++ b/www/board/agenda/views/models/posted.js.rb @@ -9,8 +9,9 @@ class Posted # fetch list of reports on first reference if not @@fetched and defined? XMLHttpRequest + @@list = JSONStorage.get('posted') || [] fetch 'https://whimsy.apache.org/board/posted-reports', :json do |list| - @@list = list if list + @@list = JSONStorage.put('posted', list) if list end @@fetched = true -- To stop receiving notification emails like this one, please contact ['"commits@whimsical.apache.org" <commits@whimsical.apache.org>'].