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 fa5d669: prefetch LDAP attributes for performance reasons
Date Sat, 23 Jan 2016 14:35:10 GMT
Commit fa5d669c73ef749e40312631e272e32d1a03af00:
    prefetch LDAP attributes for performance reasons


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                                       | ++++++++++++ -
www/roster/public_ldap_committees.rb                         | +++ -
www/roster/public_ldap_committers.rb                         | +++ ----
www/roster/public_ldap_groups.rb                             | +++ -
------------------------------------------------------------
65 changes: 55 additions, 10 deletions.
------------------------------------------------------------


diff --git a/lib/whimsy/asf/ldap.rb b/lib/whimsy/asf/ldap.rb
index f8db23f..a2ffe87 100644
--- a/lib/whimsy/asf/ldap.rb
+++ b/lib/whimsy/asf/ldap.rb
@@ -351,9 +351,30 @@ def include?(person)
       end
     end
 
+    def self.preload
+      Hash[ASF.search_one(base, "cn=*", %w(dn, memberUid)).map do |results|
+        cn = results['dn'].first[/^cn=(.*?),/, 1]
+        group = ASF::Group.find(cn)
+        members = results['memberUid']
+        group.members = members || []
+        [group, members]
+      end]
+    end
+
+    def members=(members)
+      @members = WeakRef.new(members)
+    end
+
     def members
-      ASF.search_one(base, "cn=#{name}", 'memberUid').flatten.
-        map {|uid| Person.find(uid)}
+      begin
+        members = @members[0..-1] if @members
+      rescue WeakRef::RefError
+      end
+
+      members ||= ASF.search_one(base, "cn=#{name}", 'memberUid').flatten
+      @members = members
+
+      members.map {|uid| Person.find(uid)}
     end
   end
 
@@ -364,9 +385,30 @@ def self.list(filter='cn=*')
       ASF.search_one(base, filter, 'cn').flatten.map {|cn| Committee.find(cn)}
     end
 
+    def self.preload
+      Hash[ASF.search_one(base, "cn=*", %w(dn, member)).map do |results|
+        cn = results['dn'].first[/^cn=(.*?),/, 1]
+        committee = ASF::Committee.find(cn)
+        members = results['member']
+        committee.members = members
+        [committee, members]
+      end]
+    end
+
+    def members=(members)
+      @members = WeakRef.new(members)
+    end
+
     def members
-      ASF.search_one(base, "cn=#{name}", 'member').flatten.
-        map {|uid| Person.find uid[/uid=(.*?),/,1]}
+      begin
+        members = @members[0..-1] if @members
+      rescue WeakRef::RefError
+      end
+
+      members ||= ASF.search_one(base, "cn=#{name}", 'member').flatten
+      @members = members
+
+      members.map {|uid| Person.find uid[/uid=(.*?),/,1]}
     end
 
     def dn
diff --git a/www/roster/public_ldap_committees.rb b/www/roster/public_ldap_committees.rb
index b768bf1..69ddd1e 100644
--- a/www/roster/public_ldap_committees.rb
+++ b/www/roster/public_ldap_committees.rb
@@ -25,7 +25,9 @@
 # gather committer info
 entries = {}
 
-ASF::Committee.list.sort_by {|a| a.name}.each do |entry|
+committees = ASF::Committee.preload # for performance
+
+committees.keys.sort_by {|a| a.name}.each do |entry|
     m = []
     entry.members.sort_by {|a| a.name}.each do |e|
         m << e.name
diff --git a/www/roster/public_ldap_committers.rb b/www/roster/public_ldap_committers.rb
index 9b2db0b..c278879 100644
--- a/www/roster/public_ldap_committers.rb
+++ b/www/roster/public_ldap_committers.rb
@@ -39,9 +39,9 @@
 # people entries that are not committers (in nologin)
 nonb = {}
 
-peeps = ASF::Person.preload('loginShell',{}) # needed for the banned? method
+peeps = ASF::Person.preload(['cn', 'loginShell']) # for performance
 
-ASF.committers.sort_by {|a| a.id}.each do |entry|
+peeps.sort_by {|a| a.id}.each do |entry|
     if entry.banned?
         ban[entry.id] = entry.public_name 
     else
@@ -50,8 +50,7 @@
 end
 
 peeps.sort_by {|a| a.name}.each do |e|
-  if ASF.committers.include? e
-  else
+  unless ASF.committers.include? e
      if e.banned?
          nonb[e.name] = e.public_name
      else
diff --git a/www/roster/public_ldap_groups.rb b/www/roster/public_ldap_groups.rb
index 9de7d52..ff0edbf 100644
--- a/www/roster/public_ldap_groups.rb
+++ b/www/roster/public_ldap_groups.rb
@@ -25,7 +25,9 @@
 # gather committer info
 entries = {}
 
-ASF::Group.list.sort_by {|a| a.name}.each do |entry|
+groups = ASF::Group.preload # for performance
+
+groups.keys.sort_by {|a| a.name}.each do |entry|
     next if entry.name == 'committers'
     m = []
     entry.members.sort_by {|a| a.name}.each do |e|

Mime
View raw message