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 22dbaa2: more WeakRef changes
Date Sat, 23 Jan 2016 00:48:35 GMT
Commit 22dbaa21dc46eb163ed7d8e734c30318bf7a2087:
    more WeakRef changes


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

------------------------------------------------------------
lib/whimsy/asf/ldap.rb                                       | ++++++ ------
------------------------------------------------------------
46 changes: 23 additions, 23 deletions.
------------------------------------------------------------


diff --git a/lib/whimsy/asf/ldap.rb b/lib/whimsy/asf/ldap.rb
index 2ab0cb7..3988ba1 100644
--- a/lib/whimsy/asf/ldap.rb
+++ b/lib/whimsy/asf/ldap.rb
@@ -72,13 +72,9 @@ def self.connect
     end
   end
 
-  # backwards compatibility for tools that called this interface, and
-  # a part of the refresh strategy (something that should be revisited
-  # with WeakReferences instead).
+  # backwards compatibility for tools that called this interface
   def self.init_ldap
-    return @ldap if @ldap
-    @mtime = Time.now
-    @ldap = ASF::LDAP.connect
+    @ldap ||= ASF::LDAP.connect
   end
 
   # determine where ldap.conf resides
@@ -111,30 +107,34 @@ def self.search_one(base, filter, attrs=nil)
     result
   end
 
-  def self.refresh(symbol)
-    if not @mtime or Time.now - @mtime > 300.0
-      @mtime = Time.now
-    end
-
-    if instance_variable_get("#{symbol}_mtime") != @mtime
-      instance_variable_set("#{symbol}_mtime", @mtime)
-      instance_variable_set(symbol, nil)
-    end
-  end
-
   def self.pmc_chairs
-    refresh(:@pmc_chairs)
-    @pmc_chairs ||= Service.find('pmc-chairs').members
+    begin
+      @pmc_chairs and @pmc_chairs[0..-1]
+    rescue WeakRef::RefError
+      pmc_chairs ||= Service.find('pmc-chairs').members
+      @pmc_chairs = WeakRef.new(pmc_chairs)
+      pmc_chairs
+    end
   end
 
   def self.committers
-    refresh(:@committers)
-    @committers ||= Group.find('committers').members
+    begin
+      @committers and @committers[0..-1]
+    rescue WeakRef::RefError
+      committers = Group.find('committers').members
+      @committers = WeakRef.new(committers)
+      committers
+    end
   end
 
   def self.members
-    refresh(:@members)
-    @members ||= Group.find('member').members
+    begin
+      @members and @members[0..-1]
+    rescue WeakRef::RefError
+      members ||= Group.find('member').members
+      @members = WeakRef.new(members)
+      members
+    end
   end
 
   class Base

Mime
View raw message