whimsical-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sam Ruby <ru...@apache.org>
Subject [whimsy.git] [1/1] Commit 09cf973: minimize requests for data already seen
Date Mon, 14 Mar 2016 20:16:00 GMT
Commit 09cf973c671b4a87984e5f9a553319251eb46a50:
    minimize requests for data already seen
    compute, provide, and compare digests for agendas


Branch: refs/heads/master
Author: Sam Ruby <rubys@intertwingly.net>
Committer: Sam Ruby <rubys@intertwingly.net>
Pusher: rubys <rubys@apache.org>

------------------------------------------------------------
www/board/agenda/models/agenda.rb                            | +++++++ -----
www/board/agenda/routes.rb                                   | + 
www/board/agenda/views/buttons/attend.js.rb                  | + -
www/board/agenda/views/buttons/commit.js.rb                  | + -
www/board/agenda/views/buttons/post-actions.js.rb            | + -
www/board/agenda/views/buttons/post.js.rb                    | + -
www/board/agenda/views/buttons/refresh.js.rb                 | + -
www/board/agenda/views/keyboard.js.rb                        | + -
www/board/agenda/views/layout/main.js.rb                     | ++ --
www/board/agenda/views/models/agenda.js.rb                   | +++++++ --
------------------------------------------------------------
58 changes: 36 additions, 22 deletions.
------------------------------------------------------------


diff --git a/www/board/agenda/models/agenda.rb b/www/board/agenda/models/agenda.rb
index f38591c..503d42a 100755
--- a/www/board/agenda/models/agenda.rb
+++ b/www/board/agenda/models/agenda.rb
@@ -6,6 +6,9 @@
 # This code also maintains a "working copy" of agendas when updates are
 # made that may not yet be reflected in the local svn checkout.
 #
+
+require 'digest'
+
 class Agenda
   def self.[](file)
     IPC[file]
@@ -16,16 +19,16 @@ def self.[]=(file, data)
   end
 
   def self.update_cache(file, path, contents, quick)
-    parsed = ASF::Board::Agenda.parse(contents, quick)
-    update = {mtime: (quick ? -1 : File.mtime(path)), parsed: parsed}
-    unless IPC[file] and IPC[file] == update
-      before = Agenda[file] and Agenda[file][:parsed]
-
-      Agenda[file] = update
-
-      unless quick or before == update[:parsed]
-        IPC.post type: :agenda, file: file, mtime: update[:mtime].to_f
-      end
+    update = {
+      mtime: (quick ? -1 : File.mtime(path)),
+      parsed: ASF::Board::Agenda.parse(contents, quick),
+      digest: Digest::SHA256.base64digest(contents)
+    }
+
+    current = IPC[file]
+    unless current and current[:digest] == update[:digest]
+      IPC[file] = update
+      IPC.post type: :agenda, file: file, digest: update[:digest] unless quick
     end
   end
 
@@ -138,6 +141,7 @@ def self.update(file, message, retries=20, &block)
 
       # return the result in the response
       _.method_missing(:_agenda, Agenda[file][:parsed])
+      _.method_missing(:_digest, Agenda[file][:digest])
     end
 
   ensure
diff --git a/www/board/agenda/routes.rb b/www/board/agenda/routes.rb
index 5ecca68..e32ad99 100755
--- a/www/board/agenda/routes.rb
+++ b/www/board/agenda/routes.rb
@@ -97,6 +97,7 @@
     query: params['q'],
     agenda: agenda,
     parsed: Agenda[agenda][:parsed],
+    digest: Agenda[agenda][:digest],
     etag: Agenda.uptodate(agenda) ? Agenda[agenda][:etag] : nil
   }
 
diff --git a/www/board/agenda/views/buttons/attend.js.rb b/www/board/agenda/views/buttons/attend.js.rb
index 07b4893..40e5621 100644
--- a/www/board/agenda/views/buttons/attend.js.rb
+++ b/www/board/agenda/views/buttons/attend.js.rb
@@ -40,7 +40,7 @@ def click(event)
     @disabled = true
     post 'attend', data do |response|
       @disabled = false
-      Agenda.load response.agenda
+      Agenda.load response.agenda, response.digest
     end
   end
 end
diff --git a/www/board/agenda/views/buttons/commit.js.rb b/www/board/agenda/views/buttons/commit.js.rb
index 9d8cc48..fd7264b 100644
--- a/www/board/agenda/views/buttons/commit.js.rb
+++ b/www/board/agenda/views/buttons/commit.js.rb
@@ -112,7 +112,7 @@ def change(event)
   def click(event)
     @disabled = true
     post 'commit', message: @message, initials: Pending.initials do |response|
-      Agenda.load response.agenda
+      Agenda.load response.agenda, response.digest
       Pending.load response.pending
       @disabled = false
 
diff --git a/www/board/agenda/views/buttons/post-actions.js.rb b/www/board/agenda/views/buttons/post-actions.js.rb
index 8a23f61..f96f3ef 100644
--- a/www/board/agenda/views/buttons/post-actions.js.rb
+++ b/www/board/agenda/views/buttons/post-actions.js.rb
@@ -21,7 +21,7 @@ def click(event)
     @disabled = true
     post 'post-actions', data do |response|
       @disabled = false
-      Agenda.load response.agenda
+      Agenda.load response.agenda, response.digest
     end
   end
 end
diff --git a/www/board/agenda/views/buttons/post.js.rb b/www/board/agenda/views/buttons/post.js.rb
index ab9f904..bef4d79 100644
--- a/www/board/agenda/views/buttons/post.js.rb
+++ b/www/board/agenda/views/buttons/post.js.rb
@@ -198,7 +198,7 @@ def submit(event)
       jQuery('#post-report-form').modal(:hide)
       document.body.classList.remove('modal-open')
       @disabled = false
-      Agenda.load response.agenda
+      Agenda.load response.agenda, response.digest
     end
   end
 end
diff --git a/www/board/agenda/views/buttons/refresh.js.rb b/www/board/agenda/views/buttons/refresh.js.rb
index 0df14de..9962f5d 100644
--- a/www/board/agenda/views/buttons/refresh.js.rb
+++ b/www/board/agenda/views/buttons/refresh.js.rb
@@ -14,7 +14,7 @@ def click(event)
     @disabled = true
     post 'refresh', agenda: Agenda.file do |response|
       @disabled = false
-      Agenda.load response.agenda
+      Agenda.load response.agenda, response.digest
     end
   end
 end
diff --git a/www/board/agenda/views/keyboard.js.rb b/www/board/agenda/views/keyboard.js.rb
index beca235..de6b530 100644
--- a/www/board/agenda/views/keyboard.js.rb
+++ b/www/board/agenda/views/keyboard.js.rb
@@ -81,7 +81,7 @@ def (document.body).onkeydown(event)
         Main.refresh()
         post 'refresh', agenda: Agenda.file do |response|
           clock_counter -= 1
-          Agenda.load response.agenda
+          Agenda.load response.agenda, response.digest
           Main.refresh()
         end
         return false
diff --git a/www/board/agenda/views/layout/main.js.rb b/www/board/agenda/views/layout/main.js.rb
index 549957a..7188a2d 100644
--- a/www/board/agenda/views/layout/main.js.rb
+++ b/www/board/agenda/views/layout/main.js.rb
@@ -44,7 +44,7 @@ def componentWillMount()
       Server[prop] = @@server[prop]
     end
 
-    Agenda.load(@@page.parsed)
+    Agenda.load(@@page.parsed, @@page.digest)
     Minutes.load(@@page.minutes)
     self.route(@@page.path, @@page.query)
 
@@ -129,7 +129,7 @@ def window.onresize()
     window.onresize()
 
     # if agenda is stale, fetch immediately; otherwise save etag
-    Agenda.fetch(@@page.etag)
+    Agenda.fetch(@@page.etag, @@page.digest)
 
     # start backchannel
     Events.monitor()
diff --git a/www/board/agenda/views/models/agenda.js.rb b/www/board/agenda/views/models/agenda.js.rb
index 0ca231d..a00b702 100644
--- a/www/board/agenda/views/models/agenda.js.rb
+++ b/www/board/agenda/views/models/agenda.js.rb
@@ -7,11 +7,13 @@
 class Agenda
   @@index = []
   @@etag = nil
+  @@digest = nil
 
   # (re)-load an agenda, creating instances for each item, and linking
   # each instance to their next and previous items.
-  def self.load(list)
+  def self.load(list, digest)
     return unless list
+    @@digest = digest
     @@index.clear()
     prev = nil
 
@@ -52,10 +54,10 @@ def self.load(list)
   end
 
   # fetch agenda if etag is not supplied
-  def self.fetch(etag)
+  def self.fetch(etag, digest)
     if etag
       @@etag = etag
-    else
+    elsif digest != @@digest or not @@etag
       xhr = XMLHttpRequest.new()
       xhr.open('GET', "../#{@@date}.json", true)
       xhr.setRequestHeader('If-None-Match', @@etag) if @@etag
@@ -69,6 +71,8 @@ def xhr.onreadystatechange()
       end
       xhr.send()
     end
+
+    @@digest = digest
   end
 
   # return the entire agenda
@@ -226,6 +230,11 @@ def self.file
     "board_agenda_#{@@date.gsub('-', '_')}.txt"
   end
 
+  # get the digest of the file associated with this agenda
+  def self.digest
+    @@digest
+  end
+
   # previous link for the agenda index page
   def self.prev
     result = {title: 'Help', href: 'help'}
@@ -437,7 +446,7 @@ def color
 end
 
 Events.subscribe :agenda do |message|
-  Agenda.fetch(nil) if message.file == Agenda.file
+  Agenda.fetch(nil, message.digest) if message.file == Agenda.file
 end
 
 Events.subscribe :server do |message|

Mime
View raw message