You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@whimsical.apache.org by Sam Ruby <ru...@apache.org> on 2016/03/30 21:17:16 UTC

[whimsy.git] [1/1] Commit 41db8cc: further progress towards making emeritize work

Commit 41db8ccb29e72d2f65ab0b00103eb200553a6399:
    further progress towards making emeritize work


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

------------------------------------------------------------
lib/whimsy/asf/member.rb                                     | +++++++++ --
www/roster/views/actions/memstat.json.rb                     | +++++ --
www/roster/views/actions/sascore.json.rb                     | + -
www/roster/views/committer.js.rb                             | ++ --
------------------------------------------------------------
53 changes: 42 additions, 11 deletions.
------------------------------------------------------------


diff --git a/lib/whimsy/asf/member.rb b/lib/whimsy/asf/member.rb
index 071d510..5c1bf27 100644
--- a/lib/whimsy/asf/member.rb
+++ b/lib/whimsy/asf/member.rb
@@ -3,7 +3,8 @@
 module ASF
   class Member
     include Enumerable
-    attr_accessor :full
+    @@text = nil
+    @@mtime = 0
 
     def self.find_text_by_id(value)
       new.each do |id, text|
@@ -42,14 +43,14 @@ def self.find_by_email(value)
 
     def self.status
       begin
+        @status = nil if @mtime != @@mtime
+        @mtime = @@mtime
         return Hash[@status.to_a] if @status
       rescue
       end
 
       status = {}
-      foundation = ASF::SVN.find('private/foundation')
-      return status unless foundation
-      sections = File.read("#{foundation}/members.txt").split(/(.*\n===+)/)
+      sections = ASF::Member.text.split(/(.*\n===+)/)
       sections.shift(3)
       sections.each_slice(2) do |header, text|
         header.sub!(/s\n=+/,'')
@@ -61,8 +62,7 @@ def self.status
     end
 
     def each
-      foundation = ASF::SVN['private/foundation']
-      File.read("#{foundation}/members.txt").split(/^ \*\) /).each do |section|
+      ASF::Member.text.split(/^ \*\) /).each do |section|
         id = section[/Avail ID: (.*)/,1]
         yield id, section.sub(/\n.*\n===+\s*?\n(.*\n)+.*/,'').strip if id
       end
@@ -109,6 +109,34 @@ def self.sort(source)
 
       sections.join
     end
+
+    # cache the contents of members.txt.  Primary purpose isn't performance,
+    # but rather to have a local copy that can be updated and used until
+    # the svn working copy catches up
+    def self.text
+      foundation = ASF::SVN.find('private/foundation')
+      return nil unless foundation
+
+      begin
+        text = @@text[0..-1] if @@text
+      rescue WeakRef::RefError
+        @@mtime = 0
+      end
+
+      if File.mtime("#{foundation}/members.txt").to_i > @@mtime.to_i
+        @@mtime = File.mtime("#{foundation}/members.txt")
+        text = File.read("#{foundation}/members.txt")
+        @@text = WeakRef.new(text)
+      end
+
+      text
+    end
+
+    # update local copy of members.txt
+    def self.text=text
+      @@mtime = Time.now
+      @@text = WeakRef.new(text)
+    end
   end
 
   class Person
diff --git a/www/roster/views/actions/memstat.json.rb b/www/roster/views/actions/memstat.json.rb
index 5f5759d..8786401 100644
--- a/www/roster/views/actions/memstat.json.rb
+++ b/www/roster/views/actions/memstat.json.rb
@@ -37,8 +37,11 @@
   # perform the insertion
   text.insert index, entry
 
-  # sort the text and save the result to disk
-  File.write("#{tmpdir}/members.txt", ASF::Member.sort(text))
+  # sort and save locally the updated text
+  ASF::Member.text = ASF::Member.sort(text)
+
+  # save the results to disk
+  File.write("#{tmpdir}/members.txt", ASF::Member.text)
 
   # commit changes
   rc = system ['svn', 'commit', auth, "#{tmpdir}/members.txt",
diff --git a/www/roster/views/actions/sascore.json.rb b/www/roster/views/actions/sascore.json.rb
index 4ea795e..0ae46fd 100644
--- a/www/roster/views/actions/sascore.json.rb
+++ b/www/roster/views/actions/sascore.json.rb
@@ -25,4 +25,4 @@
 end
 
 # return updated committer info
-Committer.serialize(@userid, env)
+_committer Committer.serialize(@userid, env)
diff --git a/www/roster/views/committer.js.rb b/www/roster/views/committer.js.rb
index b8ff31a..3e75f4c 100644
--- a/www/roster/views/committer.js.rb
+++ b/www/roster/views/committer.js.rb
@@ -314,13 +314,13 @@ def submit(event)
 
       complete: ->(response) do
         # reenable form for later reuse
-        Array(form[0].querySelectorAll('input')).each do |input|
+        Array(form[0].querySelectorAll('input, button')).each do |input|
           input.disabled = false
         end
       end
     )
 
-    Array(form[0].querySelectorAll('input')).each do |input|
+    Array(form[0].querySelectorAll('input, button')).each do |input|
       input.disabled = true
     end
   end