This is an automated email from the ASF dual-hosted git repository.

sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/whimsy.git


The following commit(s) were added to refs/heads/master by this push:
     new 93105412 Simplify getting emails etc
93105412 is described below

commit 9310541293c0f16d4ef4eec63c19f022df152388
Author: Sebb <[email protected]>
AuthorDate: Fri Feb 27 17:34:53 2026 +0000

    Simplify getting emails etc
---
 lib/whimsy/asf/mail.rb         | 68 +++++++++++++++++++++---------------------
 www/roster/main.rb             | 43 ++++++++++----------------
 www/roster/models/committee.rb |  8 +----
 www/roster/models/nonpmc.rb    |  8 +----
 www/roster/models/ppmc.rb      |  9 +-----
 5 files changed, 52 insertions(+), 84 deletions(-)

diff --git a/lib/whimsy/asf/mail.rb b/lib/whimsy/asf/mail.rb
index 9351df39..b15ccbb0 100644
--- a/lib/whimsy/asf/mail.rb
+++ b/lib/whimsy/asf/mail.rb
@@ -3,44 +3,44 @@ require 'weakref'
 module ASF
   # Convenience functions related to emails or mailing lists.
   class Mail
-    # return a Hash containing complete list of all known emails, and the
-    # ASF::Person that is associated with that email.
-    def self.list
-      begin
-        return @list.to_h if @list
-      rescue NoMethodError, WeakRef::RefError
-      end
-
-      list = {}
-
-      # load info from LDAP
-      people = ASF::Person.preload(['mail', 'asf-altEmail'])
-      people.each do |person|
-        (person.mail + person.alt_email).each do |mail|
-          list[mail.downcase] = person
-        end
-      end
 
-      # load all member emails in one pass
-      ASF::Member.each do |id, text|
-        Member.emails(text).each do |mail|
-          list[mail.downcase] ||= Person.find(id)
-        end
+    # return a list of people ids, their public-name, whether they are an ASF 
member, and email addresses
+    def self.people_mails
+      member_statuses = ASF::Member.member_statuses # cache the statuses. 
TODO: should be done in ASF.Member
+      people = ASF::Person.preload(['cn', 'mail','asf-altEmail'])
+      result = people.sort_by(&:id).map do |person|
+        id = person.id
+        mails = person.mail + person.alt_email + ["#{id}@apache.org"]
+        entry = {
+          id: id,
+          name: person.public_name,
+          mail: mails.map{|m| m.downcase}.uniq,
+        }
+        entry[:member] = true if member_statuses[id]
+        entry
       end
+      result
+    end
 
-      # load all ICLA emails in one pass
-      ASF::ICLA.each do |icla|
-        person = Person.find(icla.id)
-        icla.emails.each do |email|
-          list[email.downcase] ||= person
-        end
-        next if icla.noId?
-
-        list["#{icla.id.downcase}@apache.org"] ||= person
+    # return a list of people ids, their public-name, whether they are an ASF 
member, and email addresses
+    # Also return GH settings
+    # @param extra_mails additional emails derived from members and iclas
+    def self.people_mails_github(extra_mails)
+      member_statuses = ASF::Member.member_statuses # cache the statuses. 
TODO: should be done in ASF.Member
+      people = ASF::Person.preload(['cn', 
'mail','asf-altEmail','githubUsername', 'asf-githubStringID'])
+      result = people.sort_by(&:id).map do |person|
+        id = person.id
+        mails = person.mail + person.alt_email + extra_mails.fetch(id, []) + 
["#{id}@apache.org"]
+        {
+          id: id,
+          name: person.public_name,
+          mail: mails.map{|m| m.downcase}.uniq,
+          githubUsername: person.attrs['githubUsername'] || [],
+          asf_githubStringID: person.attrs['asf-githubStringID']&.first || '',
+          asf_member_status: member_statuses[person.id],
+        }
       end
-
-      @list = WeakRef.new(list)
-      list
+      result
     end
 
     # list of mailing lists that aren't actively seeking new subscribers
diff --git a/www/roster/main.rb b/www/roster/main.rb
index a2fa2111..22f6db1f 100755
--- a/www/roster/main.rb
+++ b/www/roster/main.rb
@@ -133,20 +133,7 @@ get '/committer/index.json' do
   index = nil if not index_time or Time.now-index_time >= 300
 
   if not index
-    # bulk loading the mail information makes things go faster
-    mail = Hash[ASF::Mail.list.group_by(&:last).
-      map {|person, list| [person, list.map(&:first)]}]
-
-    
ASF::Person.preload(['id','name','mail','githubUsername','asf-githubStringID'])
-    member_statuses = ASF::Member.member_statuses
-    # build a list of people, their public-names, and email addresses
-    index = ASF::Person.list.sort_by(&:id).map {|person|
-      result = {id: person.id, name: person.public_name, mail: mail[person],
-        githubUsername: person.attrs['githubUsername'] || [],
-        asf_githubStringID: person.attrs['asf-githubStringID']&.first || ''}
-      result[:asf_member_status] = member_statuses[person.id]
-      result
-    }.to_json
+    index = ASF::Mail.people_mails_github({}).to_json
 
     # cache
     index_time = Time.now
@@ -183,21 +170,21 @@ get '/committer2/index.json' do
   index2 = nil if not index2_time or Time.now-index2_time >= 300
 
   if not index2
-    # bulk loading the mail information makes things go faster
-    mail = Hash[ASF::Mail.list.group_by(&:last).
-      map {|person, list| [person, list.map(&:first)]}]
-
-    ASF::Person.preload(['id','name','mail','githubUsername', 
'asf-githubStringID'])
-    member_statuses = ASF::Member.member_statuses
-    # build a list of people, their public-names, and email addresses
-    tmp = ASF::Person.list.sort_by(&:id).map {|person|
-      result = {id: person.id, name: person.public_name, mail: mail[person],
-        githubUsername: person.attrs['githubUsername'] || [],
-        asf_githubStringID: person.attrs['asf-githubStringID']&.first || ''}
-      result[:asf_member_status] = member_statuses[person.id]
-      result
-    }
+    extra_mails = Hash.new{|h,k| h[k] = Array.new}
+    ASF::Member.list_entries([:email]).each do |status, _name, id, _lines, 
keys|
+      unless id.nil?
+        extra_mails[id] = keys[:email]
+      end
+    end
+
+    # load all ICLA emails in one pass
+    ASF::ICLA.each do |icla|
+      extra_mails[icla.id].concat icla.emails
+    end
 
+    tmp = ASF::Mail.people_mails_github(extra_mails)
+    
+    # Add ICLA details
     ASF::ICLA.each {|icla|
       if icla.noId?
         if @auth[:secretary]
diff --git a/www/roster/models/committee.rb b/www/roster/models/committee.rb
index 2a4e9076..4406e60b 100644
--- a/www/roster/models/committee.rb
+++ b/www/roster/models/committee.rb
@@ -224,15 +224,9 @@ class Committee
     @people = nil if not @people_time or Time.now-@people_time >= 300
 
     unless @people
-      # bulk loading the mail information makes things go faster
-      mail = ASF::Mail.list.group_by(&:last).transform_values {|list| 
list.map(&:first)}
 
       # build a list of people, their public-names, and email addresses
-      @people = ASF::Person.list.map {|person|
-        result = {id: person.id, name: person.public_name, mail: mail[person]}
-        result[:member] = true if person.asf_member?
-        result
-      }
+      @people = ASF::Mail.people_mails
 
       # cache
       @people_time = Time.now
diff --git a/www/roster/models/nonpmc.rb b/www/roster/models/nonpmc.rb
index e30cd2b6..3c01a76f 100644
--- a/www/roster/models/nonpmc.rb
+++ b/www/roster/models/nonpmc.rb
@@ -189,15 +189,9 @@ class NonPMC
     @people = nil if not @people_time or Time.now-@people_time >= 300
 
     unless @people
-      # bulk loading the mail information makes things go faster
-      mail = ASF::Mail.list.group_by(&:last).transform_values {|list| 
list.map(&:first)}
 
       # build a list of people, their public-names, and email addresses
-      @people = ASF::Person.list.map {|person|
-        result = {id: person.id, name: person.public_name, mail: mail[person]}
-        result[:member] = true if person.asf_member?
-        result
-      }
+      @people = ASF::Mail.people_mails
 
       # cache
       @people_time = Time.now
diff --git a/www/roster/models/ppmc.rb b/www/roster/models/ppmc.rb
index b4d0d6c1..6d3835cd 100644
--- a/www/roster/models/ppmc.rb
+++ b/www/roster/models/ppmc.rb
@@ -194,16 +194,9 @@ class PPMC
     @people = nil if not @people_time or Time.now - @people_time >= 300
 
     unless @people
-      # bulk loading the mail information makes things go faster
-      # TODO: it is still expensive
-      mail = ASF::Mail.list.group_by(&:last).transform_values {|list| 
list.map(&:first)}
 
       # build a list of people, their public-names, and email addresses
-      @people = ASF::Person.list.map {|person|
-        result = {id: person.id, name: person.public_name, mail: mail[person]}
-        result[:member] = true if person.asf_member?
-        result
-      }
+      @people = ASF::Mail.people_mails
 
       # cache
       @people_time = Time.now

Reply via email to