whimsical-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject [whimsy] branch master updated: Eliminate sort by using max
Date Thu, 24 Sep 2020 22:04:24 GMT
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 85ab178  Eliminate sort by using max
85ab178 is described below

commit 85ab1786666e22491a95a752d77ad033a5208d84
Author: Sebb <sebb@apache.org>
AuthorDate: Thu Sep 24 23:04:15 2020 +0100

    Eliminate sort by using max
---
 lib/whimsy/asf/nominees.rb                            |  2 +-
 tools/proxyhelper.rb                                  |  2 +-
 tools/vhosttest.rb                                    |  2 +-
 tools/votes2ini.rb                                    |  2 +-
 www/board/agenda/bin/remind-cronjob.rb                |  2 +-
 www/board/agenda/daemon/session.rb                    |  4 ++--
 www/board/agenda/daemon/wss.rb                        | 10 +++++-----
 www/board/agenda/models/reporter.rb                   |  2 +-
 www/board/agenda/routes.rb                            | 12 ++++++------
 www/board/agenda/views/actions/post.json.rb           |  2 +-
 www/board/agenda/views/actions/posted-reports.json.rb |  2 +-
 www/board/agenda/views/actions/reminder-text.json.rb  |  2 +-
 www/board/posted-reports.cgi                          |  2 +-
 www/committers/testauth.cgi                           |  2 +-
 www/members/meeting-util.rb                           |  2 +-
 www/members/watch.cgi                                 |  2 +-
 www/secretary/workbench/server.rb                     |  4 ++--
 www/secretary/workbench/views/actions/memapp.json.rb  |  2 +-
 www/secretary/workbench/views/memapp.json.rb          |  2 +-
 19 files changed, 30 insertions(+), 30 deletions(-)

diff --git a/lib/whimsy/asf/nominees.rb b/lib/whimsy/asf/nominees.rb
index a3bd880..2d4514d 100644
--- a/lib/whimsy/asf/nominees.rb
+++ b/lib/whimsy/asf/nominees.rb
@@ -13,7 +13,7 @@ module ASF
       end
 
       meetings = ASF::SVN['Meetings']
-      nominations = Dir[File.join(meetings, '*', 'nominated-members.txt')].sort.last.untaint
+      nominations = Dir[File.join(meetings, '*', 'nominated-members.txt')].max.untaint
 
       nominations = File.read(nominations).split(/^\s*---+--\s*/)
       nominations.shift(2)
diff --git a/tools/proxyhelper.rb b/tools/proxyhelper.rb
index bfd7e92..be37f5c 100644
--- a/tools/proxyhelper.rb
+++ b/tools/proxyhelper.rb
@@ -14,7 +14,7 @@ MEETINGS = ASF::SVN['Meetings']
 # @return reminders {"proxy@apache.org" => ["IRC line", ...]}
 # @see foundation/Meetings/*.rb for other scripts that deal with
 #   IRC log parsing, attendance marking, and proxy handling
-def reminder_lines(meeting = File.basename(Dir[File.join(MEETINGS, '2*')].sort.last).untaint)
+def reminder_lines(meeting = File.basename(Dir[File.join(MEETINGS, '2*')].max).untaint)
   lines = IO.read(File.join(MEETINGS, meeting, 'proxies'))
   proxylist = lines.scan(/\s\s(.{25})(.*?)\((.*?)\)/).map { |l| [l[0].strip, l[1].strip,
l[2]]} # [["Shane Curcuru    ", "David Fisher ", "wave"], ...]
   copyproxy = Hash.new{|h,k| h[k] = [] }
diff --git a/tools/vhosttest.rb b/tools/vhosttest.rb
index 5f1758d..cee3269 100755
--- a/tools/vhosttest.rb
+++ b/tools/vhosttest.rb
@@ -24,7 +24,7 @@ require 'yaml'
 require "#{IP}/modules/vhosts_whimsy/lib/puppet/parser/functions/preprocess_vhosts.rb"
 
 yaml = Dir["#{IP}/data/nodes/whimsy-vm*.apache.org.yaml"].
-  sort_by {|path| path[/-vm(\d+)/, 1].to_i}.last
+  max_by {|path| path[/-vm(\d+)/, 1].to_i}
 facts = YAML.load_file(yaml)['vhosts_whimsy::vhosts::vhosts']['whimsy-vm-443']
 ldap = ASF::LDAP::RO_HOSTS.join(' ') # to be closer to live site
 
diff --git a/tools/votes2ini.rb b/tools/votes2ini.rb
index 010a20c..668a3b2 100755
--- a/tools/votes2ini.rb
+++ b/tools/votes2ini.rb
@@ -6,7 +6,7 @@
 
 require 'json'
 
-raw_file = Dir["/srv/svn/Meetings/*/raw_board_votes.json"].sort.last
+raw_file = Dir["/srv/svn/Meetings/*/raw_board_votes.json"].max
 raw_votes = JSON.parse(IO.read(raw_file))
 txt_file = raw_file.sub('.json', '.txt')
 ini_file = File.dirname(raw_file) + '/board_nominations.ini'
diff --git a/www/board/agenda/bin/remind-cronjob.rb b/www/board/agenda/bin/remind-cronjob.rb
index dc1243b..1341747 100644
--- a/www/board/agenda/bin/remind-cronjob.rb
+++ b/www/board/agenda/bin/remind-cronjob.rb
@@ -24,7 +24,7 @@ require './models/agenda'
 reminder = eval(File.read("views/actions/reminder-text.json.rb"))
 
 # send reminders
-@agenda = File.basename(Dir[File.join(FOUNDATION_BOARD, 'board_agenda_*.txt')].sort.last)
+@agenda = File.basename(Dir[File.join(FOUNDATION_BOARD, 'board_agenda_*.txt')].max)
 @from = "Whimsy <no-reply@apache.org>"
 @dryrun = true
 @subject = reminder[:subject]
diff --git a/www/board/agenda/daemon/session.rb b/www/board/agenda/daemon/session.rb
index 83b9cce..e48faad 100644
--- a/www/board/agenda/daemon/session.rb
+++ b/www/board/agenda/daemon/session.rb
@@ -36,13 +36,13 @@ class Session
 
   # find the latest session for the given user, creating one if necessary.
   def self.user(id)
-    session = @@users[id].sort_by {|session| session[:mtime]}.last
+    session = @@users[id].max_by {|session| session[:mtime]}
     session = nil if session and session[:mtime] < Time.now - DAY
 
     # if not found, try refreshing data from disk and try again
     if not session
       Session.load
-      session = @@users[id].sort_by {|session| session[:mtime]}.last
+      session = @@users[id].max_by {|session| session[:mtime]}
       session = nil if session and session[:mtime] < Time.now - DAY
     end
 
diff --git a/www/board/agenda/daemon/wss.rb b/www/board/agenda/daemon/wss.rb
index 5b9d3d9..279202f 100755
--- a/www/board/agenda/daemon/wss.rb
+++ b/www/board/agenda/daemon/wss.rb
@@ -20,10 +20,10 @@ require_relative './channel'
 options = OpenStruct.new
 options.host = '0.0.0.0'
 options.port = 34234
-options.privkey = Dir['/etc/letsencrypt/live/*/privkey.pem'].
-  sort_by {|file| File.mtime file}.last
-options.chain = Dir['/etc/letsencrypt/live/*/fullchain.pem'].
-  sort_by {|file| File.mtime file}.last
+options.privkey =
+  Dir['/etc/letsencrypt/live/*/privkey.pem'].max_by {|f| File.mtime f}
+options.chain =
+  Dir['/etc/letsencrypt/live/*/fullchain.pem'].max_by {|f| File.mtime f}
 options.kill = false
 options.timeout = 900
 
@@ -85,7 +85,7 @@ def restart_process
   exec RbConfig.ruby, File.expand_path(__FILE__), *ARGV
 end
 
-listener = Listen.to(__dir__) do |modified, added, removed|
+listener = Listen.to(__dir__) do
   restart_process
 end
 listener.start
diff --git a/www/board/agenda/models/reporter.rb b/www/board/agenda/models/reporter.rb
index 8c0565b..1d08854 100644
--- a/www/board/agenda/models/reporter.rb
+++ b/www/board/agenda/models/reporter.rb
@@ -15,7 +15,7 @@ class Reporter
     changed = false
 
     agenda_file = File.basename(
-      Dir["#{FOUNDATION_BOARD}/board_agenda_*.txt"].sort.last).untaint
+      Dir["#{FOUNDATION_BOARD}/board_agenda_*.txt"].max).untaint
 
     if ENV['RACK_ENV'] == 'test'
       return {agenda: agenda_file, drafts: []}
diff --git a/www/board/agenda/routes.rb b/www/board/agenda/routes.rb
index 69018b4..243f5fd 100755
--- a/www/board/agenda/routes.rb
+++ b/www/board/agenda/routes.rb
@@ -7,14 +7,14 @@ UNAVAILABLE = Status.updates_disallowed_reason # are updates disallowed?
 
 # redirect root to latest agenda
 get '/' do
-  agenda = dir('board_agenda_*.txt').sort.last
+  agenda = dir('board_agenda_*.txt').max
   pass unless agenda
   redirect "#{request.path}#{agenda[/\d+_\d+_\d+/].gsub('_', '-')}/"
 end
 
 # alias for latest agenda
 get '/latest/' do
-  agenda = dir('board_agenda_*.txt').sort.last
+  agenda = dir('board_agenda_*.txt').max
   pass unless agenda
   call env.merge(
     'PATH_INFO' => "/#{agenda[/\d+_\d+_\d+/].gsub('_', '-')}/"
@@ -23,7 +23,7 @@ end
 
 # alias for latest agenda in JSON format
 get '/latest.json' do
-  agenda = dir('board_agenda_*.txt').sort.last
+  agenda = dir('board_agenda_*.txt').max
   pass unless agenda
   call env.merge!(
     'PATH_INFO' => "/#{agenda[/\d+_\d+_\d+/].gsub('_', '-')}.json"
@@ -68,7 +68,7 @@ end
 # redirect shepherd to latest agenda
 get '/shepherd' do
   user=ASF::Person.find(env.user).public_name.split(' ').first
-  agenda = dir('board_agenda_*.txt').sort.last
+  agenda = dir('board_agenda_*.txt').max
   pass unless agenda
   redirect File.dirname(request.path) +
     "/#{agenda[/\d+_\d+_\d+/].gsub('_', '-')}/shepherd/#{user}"
@@ -76,7 +76,7 @@ end
 
 # redirect missing to missing page for the latest agenda
 get '/missing' do
-  agenda = dir('board_agenda_*.txt').sort.last
+  agenda = dir('board_agenda_*.txt').max
   pass unless agenda # this will result in a 404
 
   # Support for sending out reminders before the agenda is created.
@@ -550,7 +550,7 @@ get '/new' do
   @owner = ASF::Board::ShepherdStream.new
 
   # Get list of unpublished and unapproved minutes
-  draft = YAML.load_file(Dir["#{AGENDA_WORK}/board_minutes*.yml"].sort.last)
+  draft = YAML.load_file(Dir["#{AGENDA_WORK}/board_minutes*.yml"].max)
   @minutes = dir("board_agenda_*.txt").
     map {|file| Date.parse(file[/\d[_\d]+/].gsub('_', '-'))}.
     reject {|date| date >= @meeting.to_date}.
diff --git a/www/board/agenda/views/actions/post.json.rb b/www/board/agenda/views/actions/post.json.rb
index 4d6a9e5..d9773b8 100644
--- a/www/board/agenda/views/actions/post.json.rb
+++ b/www/board/agenda/views/actions/post.json.rb
@@ -87,7 +87,7 @@ Agenda.update(@agenda, @message, auth: alternate_credentials) do |agenda|
     # add item letter to title
     discussion = agenda[/ 8\. Discussion Items.*\n 9\./m]
     items = discussion.scan(/^    ([A-Z]+)\./).flatten
-    item = items.empty? ? 'A' : items.sort.last.succ
+    item = items.empty? ? 'A' : items.max.succ
     title = "    #{item}. #{@title}\n\n"
 
     # update the commit message that will be used
diff --git a/www/board/agenda/views/actions/posted-reports.json.rb b/www/board/agenda/views/actions/posted-reports.json.rb
index 9b48693..1df07a5 100755
--- a/www/board/agenda/views/actions/posted-reports.json.rb
+++ b/www/board/agenda/views/actions/posted-reports.json.rb
@@ -63,7 +63,7 @@ end
 
 # Get a list of missing board reports
 agendas = Dir[File.join(ASF::SVN['foundation_board'], 'board_agenda_*.txt')]
-parsed = ASF::Board::Agenda.parse(IO.read(agendas.sort.last.untaint), true)
+parsed = ASF::Board::Agenda.parse(IO.read(agendas.max.untaint), true)
 missing = parsed.select {|item| item['missing']}.
   map {|item| item['title'].downcase}
 
diff --git a/www/board/agenda/views/actions/reminder-text.json.rb b/www/board/agenda/views/actions/reminder-text.json.rb
index ac6508f..76769ba 100644
--- a/www/board/agenda/views/actions/reminder-text.json.rb
+++ b/www/board/agenda/views/actions/reminder-text.json.rb
@@ -6,7 +6,7 @@ require 'active_support/time'
 template = File.read("#{FOUNDATION_BOARD}/templates/#@reminder.mustache")
 
 # find the latest agenda
-agenda = Dir["#{FOUNDATION_BOARD}/board_agenda_*.txt"].sort.last.untaint
+agenda = Dir["#{FOUNDATION_BOARD}/board_agenda_*.txt"].max.untaint
 
 # determine meeting time
 meeting = ASF::Board.nextMeeting
diff --git a/www/board/posted-reports.cgi b/www/board/posted-reports.cgi
index 3d075aa..c8be930 100755
--- a/www/board/posted-reports.cgi
+++ b/www/board/posted-reports.cgi
@@ -66,7 +66,7 @@ _html do
     ) do
       # Get a list of missing board reports from the agenda itself
       Dir.chdir ASF::SVN['foundation_board']
-      agenda = Dir['board_agenda_*.txt'].sort.last
+      agenda = Dir['board_agenda_*.txt'].max
       parsed = ASF::Board::Agenda.parse(IO.read(agenda.untaint), true)
       missing = parsed.select {|item| item['missing']}.
         map {|item| item['title'].downcase}
diff --git a/www/committers/testauth.cgi b/www/committers/testauth.cgi
index f930cb7..76af603 100755
--- a/www/committers/testauth.cgi
+++ b/www/committers/testauth.cgi
@@ -23,7 +23,7 @@ _html do
     }
   ) do
     FOUNDATION_BOARD = ASF::SVN['foundation_board']
-    agendafile = Dir[File.join(FOUNDATION_BOARD, 'board_agenda_*.txt')].sort.last.untaint
+    agendafile = Dir[File.join(FOUNDATION_BOARD, 'board_agenda_*.txt')].max.untaint
     agenda = ASF::Board::Agenda.parse(File.read(agendafile))
     roll = agenda.find {|item| item['title'] == 'Roll Call'}
 
diff --git a/www/members/meeting-util.rb b/www/members/meeting-util.rb
index 9575c5c..d61cb11 100644
--- a/www/members/meeting-util.rb
+++ b/www/members/meeting-util.rb
@@ -77,7 +77,7 @@ class MeetingUtil
 
   # Get the latest available Meetings dir
   def self.get_latest(mtg_root)
-    return Dir[File.join(mtg_root, '2*')].sort.last
+    return Dir[File.join(mtg_root, '2*')].max
   end
   # Get the second latest available Meetings dir
   def self.get_previous(mtg_root)
diff --git a/www/members/watch.cgi b/www/members/watch.cgi
index 526c658..3012396 100755
--- a/www/members/watch.cgi
+++ b/www/members/watch.cgi
@@ -32,7 +32,7 @@ _html do
     # start with the Watch List itself
     watch_list = ASF::Person.member_watch_list.keys
     meeting =
-      File.dirname(Dir[File.join(meetings, '*', 'nominated-members.txt')].sort.last).untaint
+      File.dirname(Dir[File.join(meetings, '*', 'nominated-members.txt')].max).untaint
 
     txt = File.read(File.join(meeting, 'nominated-members.txt'))
     nominations = txt.scan(/^---+\n\s*\w+.*<(\S+)@apache.org>/).flatten
diff --git a/www/secretary/workbench/server.rb b/www/secretary/workbench/server.rb
index 6fc618a..fb84e16 100644
--- a/www/secretary/workbench/server.rb
+++ b/www/secretary/workbench/server.rb
@@ -61,7 +61,7 @@ get '/' do
 
   # determine latest month for which there are messages
   archives = Dir[File.join(ARCHIVE, '*.yml')].select {|name| name =~ %r{/\d{6}\.yml$}}
-  @mbox = archives.empty? ? nil : File.basename(archives.sort.last, '.yml')
+  @mbox = archives.empty? ? nil : File.basename(archives.max, '.yml')
   if @mbox
     @mbox = [Date.today.strftime('%Y%m'), @mbox].min
     @messages = Mailbox.new(@mbox).client_headers.select do |message|
@@ -186,7 +186,7 @@ get %r{/(\d{6})/(\w+)/_index_} do |month, hash|
   # Section 4.1 of the ASF bylaws provides requirements for when membership
   # applications can be accepted.  Two days are added to cover the adjournment
   # period of the meeting during which the vote takes place.
-  received = Dir["#{ASF::SVN['Meetings']}/2*/memapp-received.txt"].sort.last
+  received = Dir["#{ASF::SVN['Meetings']}/2*/memapp-received.txt"].max
   @meeting = Date.today - Date.parse(received[/\d{8}/]) <= 32 rescue true # rescue crash
in local testing
 
   _html :parts
diff --git a/www/secretary/workbench/views/actions/memapp.json.rb b/www/secretary/workbench/views/actions/memapp.json.rb
index ff6705e..1dd1497 100644
--- a/www/secretary/workbench/views/actions/memapp.json.rb
+++ b/www/secretary/workbench/views/actions/memapp.json.rb
@@ -148,7 +148,7 @@ end
 
 task "svn commit memapp-received.text" do
   meetings = ASF::SVN['Meetings']
-  file = Dir["#{meetings}/2*/memapp-received.txt"].sort.last.untaint
+  file = Dir["#{meetings}/2*/memapp-received.txt"].max.untaint
   received = File.read(file)
   if received =~ /^no\s+\w+\s+\w+\s+\w+\s+#{@availid}\s/
     received[/^(no )\s+\w+\s+\w+\s+\w+\s+#{@availid}\s/,1] = 'yes'
diff --git a/www/secretary/workbench/views/memapp.json.rb b/www/secretary/workbench/views/memapp.json.rb
index ea19305..77f7c98 100644
--- a/www/secretary/workbench/views/memapp.json.rb
+++ b/www/secretary/workbench/views/memapp.json.rb
@@ -2,7 +2,7 @@
 
 # find latest memapp-received.txt file in the foundation/Meetings directory
 meetings = ASF::SVN['Meetings']
-received = Dir["#{meetings}/2*/memapp-received.txt"].sort.last.untaint
+received = Dir["#{meetings}/2*/memapp-received.txt"].max.untaint
 
 # extract contents
 pattern = /^\w+\s+(\w+)\s+(\w+)\s+(\w+)\s+(\w+)\s+(.*?)\s*\n/


Mime
View raw message