From a2c246f0ce66374ad2652c5d520574b941eff326 Mon Sep 17 00:00:00 2001 From: Chris Colvard Date: Tue, 27 Mar 2018 16:38:51 -0400 Subject: [PATCH 1/6] Update db/schema.rb so it has the correct timestamp of latest migration --- db/schema.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/schema.rb b/db/schema.rb index f5707a0228..7ba2d05bba 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20171120190443) do +ActiveRecord::Schema.define(version: 20171130201127) do create_table "annotations", force: :cascade do |t| t.string "uuid" From 760e5c25c16941a96ec99a49acfb607a88b79f2c Mon Sep 17 00:00:00 2001 From: Chris Want Date: Wed, 28 Mar 2018 14:32:02 -0600 Subject: [PATCH 2/6] Find `lsof`, if available. --- lib/avalon/batch.rb | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/avalon/batch.rb b/lib/avalon/batch.rb index 79a4f9c445..3327847f9d 100644 --- a/lib/avalon/batch.rb +++ b/lib/avalon/batch.rb @@ -27,12 +27,21 @@ class Error < ::Exception; end class IncompletePackageError < Error; end def self.find_open_files(files, base_directory = '.') + result = [] + lsof = (['/usr/sbin', '/usr/bin'] + ENV['PATH'].split(File::PATH_SEPARATOR)). + map { |path| "#{path}/lsof" }.find do |executable| + File.executable?(executable) + end + unless lsof + Rails.logger.warn('lsof missing; continuing without open file checking') + return result + end + args = files.collect { |p| %{"#{p}"} }.join(' ') Dir.chdir(base_directory) do - result = [] begin Timeout.timeout(5) do - status = `/usr/sbin/lsof -Fcpan0 #{args}` + status = `#{lsof} -Fcpan0 #{args}` statuses = status.split(/[\u0000\n]+/) statuses.in_groups_of(4) do |group| file_status = Hash[group.compact.collect { |s| [s[0].to_sym,s[1..-1]] }] @@ -42,9 +51,6 @@ def self.find_open_files(files, base_directory = '.') end end end - rescue Errno::ENOENT - # lsof doesn't exist so bail - Rails.logger.warn('lsof missing; continuing without open file checking') rescue Timeout::Error # lsof didn't return so bail Rails.logger.warn('lsof blocking; continuing without open file checking') From 7664189dfd2ead34cd13ea85c2ce645a4e70ae71 Mon Sep 17 00:00:00 2001 From: Chris Want Date: Thu, 29 Mar 2018 10:14:29 -0600 Subject: [PATCH 3/6] Make rubocop happy and add vendor/bundle to .gitignore. --- .gitignore | 1 + lib/avalon/batch.rb | 48 ++++++++++++++++++++++++++------------------- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index 392f35f4b1..c355222160 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ # Ignore bundler config. /.bundle +vendor/bundle # Ignore the default SQLite database. /db/*.sqlite3 diff --git a/lib/avalon/batch.rb b/lib/avalon/batch.rb index 3327847f9d..e9a10139c6 100644 --- a/lib/avalon/batch.rb +++ b/lib/avalon/batch.rb @@ -23,41 +23,49 @@ module Avalon module Batch - class Error < ::Exception; end - class IncompletePackageError < Error; end + class Error < StandardError; end + class IncompletePackageError < StandardError; end def self.find_open_files(files, base_directory = '.') - result = [] - lsof = (['/usr/sbin', '/usr/bin'] + ENV['PATH'].split(File::PATH_SEPARATOR)). - map { |path| "#{path}/lsof" }.find do |executable| - File.executable?(executable) - end + found_files = [] + lsof = find_lsof unless lsof Rails.logger.warn('lsof missing; continuing without open file checking') - return result + return found_files end - args = files.collect { |p| %{"#{p}"} }.join(' ') + args = files.collect { |p| %("#{p}") }.join(' ') Dir.chdir(base_directory) do begin Timeout.timeout(5) do - status = `#{lsof} -Fcpan0 #{args}` - statuses = status.split(/[\u0000\n]+/) - statuses.in_groups_of(4) do |group| - file_status = Hash[group.compact.collect { |s| [s[0].to_sym,s[1..-1]] }] - if file_status.has_key?(:n) and File.file?(file_status[:n]) and - (file_status[:a] =~ /w/ or file_status[:c] == 'scp') - result << file_status[:n] - end - end + output = `#{lsof} -Fcpan0 #{args}` + found_files = extract_files_from_lsof_output(output) end rescue Timeout::Error - # lsof didn't return so bail Rails.logger.warn('lsof blocking; continuing without open file checking') end - result + found_files end end + def self.find_lsof + (['/usr/sbin', '/usr/bin'] + ENV['PATH'].split(File::PATH_SEPARATOR)) + .map { |path| "#{path}/lsof" }.find do |executable| + File.executable?(executable) + end + end + + def self.extract_files_from_lsof_output(output) + found_files = [] + statuses = output.split(/[\u0000\n]+/) + statuses.in_groups_of(4) do |group| + file_status = Hash[group.compact.collect { |s| [s[0].to_sym, s[1..-1]] }] + if file_status.key?(:n) && File.file?(file_status[:n]) && + (file_status[:a] =~ /w/ || file_status[:c] == 'scp') + found_files << file_status[:n] + end + end + found_files + end end end From 76d817961741082562c61e7d52829c4664304b7e Mon Sep 17 00:00:00 2001 From: Chris Want Date: Thu, 29 Mar 2018 10:41:44 -0600 Subject: [PATCH 4/6] Remove a couple of unused exceptions. --- lib/avalon/batch.rb | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/avalon/batch.rb b/lib/avalon/batch.rb index e9a10139c6..ed3ac1cc07 100644 --- a/lib/avalon/batch.rb +++ b/lib/avalon/batch.rb @@ -23,9 +23,6 @@ module Avalon module Batch - class Error < StandardError; end - class IncompletePackageError < StandardError; end - def self.find_open_files(files, base_directory = '.') found_files = [] lsof = find_lsof From 7ae3c359416acdf3e8c2d2932430195eadd14389 Mon Sep 17 00:00:00 2001 From: Chris Want Date: Thu, 29 Mar 2018 10:54:22 -0600 Subject: [PATCH 5/6] Move return statement and disable line length cop for a method with the ideal number of lines. --- lib/avalon/batch.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/avalon/batch.rb b/lib/avalon/batch.rb index ed3ac1cc07..79224f4d51 100644 --- a/lib/avalon/batch.rb +++ b/lib/avalon/batch.rb @@ -23,6 +23,8 @@ module Avalon module Batch + # Breaking the next method up further would only obscure logic + # rubocop:disable Metrics/MethodLength def self.find_open_files(files, base_directory = '.') found_files = [] lsof = find_lsof @@ -41,9 +43,10 @@ def self.find_open_files(files, base_directory = '.') rescue Timeout::Error Rails.logger.warn('lsof blocking; continuing without open file checking') end - found_files end + found_files end + # rubocop:enable Metrics/MethodLength def self.find_lsof (['/usr/sbin', '/usr/bin'] + ENV['PATH'].split(File::PATH_SEPARATOR)) From f9d0dc75c4a592dd37b9d00ed4d2099855ac74c7 Mon Sep 17 00:00:00 2001 From: Chris Colvard Date: Thu, 29 Mar 2018 14:47:01 -0400 Subject: [PATCH 6/6] Use bootsnap to make app loading 50% faster --- Gemfile | 1 + Gemfile.lock | 3 +++ config/boot.rb | 1 + 3 files changed, 5 insertions(+) diff --git a/Gemfile b/Gemfile index c184336804..0960dc38d3 100644 --- a/Gemfile +++ b/Gemfile @@ -3,6 +3,7 @@ source 'https://rubygems.org' # Core rails gem 'rails', '4.2.9' gem 'sqlite3' +gem 'bootsnap', require: false # Assets gem 'coffee-rails', '~> 4.1.0' diff --git a/Gemfile.lock b/Gemfile.lock index 85e140e785..f22cfcfd72 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -255,6 +255,8 @@ GEM blacklight (~> 6.0) cancancan (~> 1.8) deprecation (~> 1.0) + bootsnap (1.2.1) + msgpack (~> 1.0) bootstrap-sass (3.3.7) autoprefixer-rails (>= 5.2.1) sass (>= 3.3.4) @@ -857,6 +859,7 @@ DEPENDENCIES aws-sdk-rails bixby blacklight (= 6.11.0) + bootsnap bootstrap-toggle-rails! bootstrap_form browse-everything (~> 0.13.0) diff --git a/config/boot.rb b/config/boot.rb index 6b750f00b1..bf929cd852 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -1,3 +1,4 @@ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) require 'bundler/setup' # Set up gems listed in the Gemfile. +require 'bootsnap/setup'