Skip to content

Commit

Permalink
Merge pull request #164 from CDLUC3/oct2024a
Browse files Browse the repository at this point in the history
Oct2024a - fuzzy search and additional error handling
  • Loading branch information
terrywbrady authored Nov 1, 2024
2 parents 80db48d + e8b5ce5 commit b22c306
Show file tree
Hide file tree
Showing 13 changed files with 146 additions and 74 deletions.
132 changes: 66 additions & 66 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,68 +8,68 @@ GIT
GEM
remote: http://rubygems.org/
specs:
actioncable (6.1.7.8)
actionpack (= 6.1.7.8)
activesupport (= 6.1.7.8)
actioncable (6.1.7.9)
actionpack (= 6.1.7.9)
activesupport (= 6.1.7.9)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
actionmailbox (6.1.7.8)
actionpack (= 6.1.7.8)
activejob (= 6.1.7.8)
activerecord (= 6.1.7.8)
activestorage (= 6.1.7.8)
activesupport (= 6.1.7.8)
actionmailbox (6.1.7.9)
actionpack (= 6.1.7.9)
activejob (= 6.1.7.9)
activerecord (= 6.1.7.9)
activestorage (= 6.1.7.9)
activesupport (= 6.1.7.9)
mail (>= 2.7.1)
actionmailer (6.1.7.8)
actionpack (= 6.1.7.8)
actionview (= 6.1.7.8)
activejob (= 6.1.7.8)
activesupport (= 6.1.7.8)
actionmailer (6.1.7.9)
actionpack (= 6.1.7.9)
actionview (= 6.1.7.9)
activejob (= 6.1.7.9)
activesupport (= 6.1.7.9)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0)
actionpack (6.1.7.8)
actionview (= 6.1.7.8)
activesupport (= 6.1.7.8)
actionpack (6.1.7.9)
actionview (= 6.1.7.9)
activesupport (= 6.1.7.9)
rack (~> 2.0, >= 2.0.9)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.2.0)
actiontext (6.1.7.8)
actionpack (= 6.1.7.8)
activerecord (= 6.1.7.8)
activestorage (= 6.1.7.8)
activesupport (= 6.1.7.8)
actiontext (6.1.7.9)
actionpack (= 6.1.7.9)
activerecord (= 6.1.7.9)
activestorage (= 6.1.7.9)
activesupport (= 6.1.7.9)
nokogiri (>= 1.8.5)
actionview (6.1.7.8)
activesupport (= 6.1.7.8)
actionview (6.1.7.9)
activesupport (= 6.1.7.9)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
activejob (6.1.7.8)
activesupport (= 6.1.7.8)
activejob (6.1.7.9)
activesupport (= 6.1.7.9)
globalid (>= 0.3.6)
activemodel (6.1.7.8)
activesupport (= 6.1.7.8)
activemodel (6.1.7.9)
activesupport (= 6.1.7.9)
activemodel-serializers-xml (1.0.3)
activemodel (>= 5.0.0.a)
activesupport (>= 5.0.0.a)
builder (~> 3.1)
activerecord (6.1.7.8)
activemodel (= 6.1.7.8)
activesupport (= 6.1.7.8)
activerecord (6.1.7.9)
activemodel (= 6.1.7.9)
activesupport (= 6.1.7.9)
activeresource (6.1.3)
activemodel (>= 6.0)
activemodel-serializers-xml (~> 1.0)
activesupport (>= 6.0)
activestorage (6.1.7.8)
actionpack (= 6.1.7.8)
activejob (= 6.1.7.8)
activerecord (= 6.1.7.8)
activesupport (= 6.1.7.8)
activestorage (6.1.7.9)
actionpack (= 6.1.7.9)
activejob (= 6.1.7.9)
activerecord (= 6.1.7.9)
activesupport (= 6.1.7.9)
marcel (~> 1.0)
mini_mime (>= 1.1.0)
activesupport (6.1.7.8)
activesupport (6.1.7.9)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
Expand All @@ -82,19 +82,19 @@ GEM
ansi (1.5.0)
ast (2.4.2)
aws-eventstream (1.3.0)
aws-partitions (1.989.0)
aws-sdk-core (3.209.1)
aws-partitions (1.992.0)
aws-sdk-core (3.211.0)
aws-eventstream (~> 1, >= 1.3.0)
aws-partitions (~> 1, >= 1.651.0)
aws-partitions (~> 1, >= 1.992.0)
aws-sigv4 (~> 1.9)
jmespath (~> 1, >= 1.6.1)
aws-sdk-ec2 (1.481.0)
aws-sdk-core (~> 3, >= 3.207.0)
aws-sdk-ec2 (1.483.0)
aws-sdk-core (~> 3, >= 3.210.0)
aws-sigv4 (~> 1.5)
aws-sdk-ssm (1.182.0)
aws-sdk-core (~> 3, >= 3.207.0)
aws-sdk-ssm (1.183.0)
aws-sdk-core (~> 3, >= 3.210.0)
aws-sigv4 (~> 1.5)
aws-sigv4 (1.10.0)
aws-sigv4 (1.10.1)
aws-eventstream (~> 1, >= 1.0.2)
base64 (0.2.0)
bcrypt_pbkdf (1.1.1)
Expand Down Expand Up @@ -152,7 +152,7 @@ GEM
debase-ruby_core_source (>= 0.10.12)
debase-ruby_core_source (3.3.6)
diff-lcs (1.5.1)
diffy (3.4.2)
diffy (3.4.3)
docile (1.4.1)
domain_name (0.6.20240107)
ed25519 (1.3.0)
Expand Down Expand Up @@ -271,20 +271,20 @@ GEM
rack
rack-test (2.1.0)
rack (>= 1.3)
rails (6.1.7.8)
actioncable (= 6.1.7.8)
actionmailbox (= 6.1.7.8)
actionmailer (= 6.1.7.8)
actionpack (= 6.1.7.8)
actiontext (= 6.1.7.8)
actionview (= 6.1.7.8)
activejob (= 6.1.7.8)
activemodel (= 6.1.7.8)
activerecord (= 6.1.7.8)
activestorage (= 6.1.7.8)
activesupport (= 6.1.7.8)
rails (6.1.7.9)
actioncable (= 6.1.7.9)
actionmailbox (= 6.1.7.9)
actionmailer (= 6.1.7.9)
actionpack (= 6.1.7.9)
actiontext (= 6.1.7.9)
actionview (= 6.1.7.9)
activejob (= 6.1.7.9)
activemodel (= 6.1.7.9)
activerecord (= 6.1.7.9)
activestorage (= 6.1.7.9)
activesupport (= 6.1.7.9)
bundler (>= 1.15.0)
railties (= 6.1.7.8)
railties (= 6.1.7.9)
sprockets-rails (>= 2.0.0)
rails-dom-testing (2.2.0)
activesupport (>= 5.0.0)
Expand All @@ -293,9 +293,9 @@ GEM
rails-html-sanitizer (1.6.0)
loofah (~> 2.21)
nokogiri (~> 1.14)
railties (6.1.7.8)
actionpack (= 6.1.7.8)
activesupport (= 6.1.7.8)
railties (6.1.7.9)
actionpack (= 6.1.7.9)
activesupport (= 6.1.7.9)
method_source
rake (>= 12.2)
thor (~> 1.0)
Expand All @@ -317,7 +317,7 @@ GEM
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
rexml (3.3.8)
rspec-core (3.13.1)
rspec-core (3.13.2)
rspec-support (~> 3.13.0)
rspec-expectations (3.13.3)
diff-lcs (>= 1.2.0, < 2.0)
Expand All @@ -334,7 +334,7 @@ GEM
rspec-mocks (~> 3.13)
rspec-support (~> 3.13)
rspec-support (3.13.1)
rubocop (1.66.1)
rubocop (1.67.0)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
Expand All @@ -346,7 +346,7 @@ GEM
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.32.3)
parser (>= 3.3.1.0)
ruby-prof (1.7.0)
ruby-prof (1.7.1)
ruby-progressbar (1.13.0)
rubyzip (2.3.2)
selenium-webdriver (4.25.0)
Expand All @@ -373,7 +373,7 @@ GEM
actionpack (>= 6.1)
activesupport (>= 6.1)
sprockets (>= 3.0.0)
sshkit (1.23.1)
sshkit (1.23.2)
base64
net-scp (>= 1.1.2)
net-sftp (>= 2.1.2)
Expand Down
9 changes: 8 additions & 1 deletion app/controllers/collection_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,17 @@ def find_by_localid(collection_ark, term)
end

def find_by_file_name(collection_ark, term)
if term =~ /\*/ && current_uid != LDAP_CONFIG['guest_user']
where = 'inv_files.pathname like ?'
val = "producer/#{term.gsub('*', '%')}"
else
where = 'inv_files.pathname = ?'
val = "producer/#{term}"
end
InvObject
.joins(:inv_collections, :inv_files)
.where('inv_collections.ark = ?', collection_ark)
.where('inv_files.pathname = ?', "producer/#{term}")
.where(where, val)
.includes(:inv_versions)
.quickloadhack
.limit(10)
Expand Down
8 changes: 8 additions & 0 deletions app/controllers/object_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@ def audit_replic
@count_by_status = @object.audit_replic_stats(@datestr)
end

def force_fail
# :nocov:
merritt_retry_block do
raise StandardError, 'force fail'
end
# :nocov:
end

private

def check_atom_group_permissions
Expand Down
9 changes: 8 additions & 1 deletion app/controllers/owner_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,17 @@ def find_by_localid(owner, term)
end

def find_by_file_name(owner, term)
if term =~ /\*/ && current_uid != LDAP_CONFIG['guest_user']
where = 'inv_files.pathname like ?'
val = "producer/#{term.gsub('*', '%')}"
else
where = 'inv_files.pathname = ?'
val = "producer/#{term}"
end
InvObject
.joins(:inv_owner, :inv_files)
.where('inv_owners.ark = ?', owner.ark)
.where('inv_files.pathname = ?', "producer/#{term}")
.where(where, val)
.includes(:inv_versions)
.quickloadhack
.limit(10)
Expand Down
4 changes: 3 additions & 1 deletion app/lib/merritt_retry_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ def merritt_retry_block
retries += 1
if retries > RETRY_LIMIT
Rails.logger.error('Retries exhausted. Clearing all active connections.')
ActiveRecord::Base.clear_active_connections!
# ActiveRecord::Base.clear_active_connections!
ActiveRecord::Base.clear_all_connections!
# yet to try: flush_idle_connections
raise RetryException, e
end

Expand Down
2 changes: 2 additions & 0 deletions app/models/inv_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ def inv_collection
end

def group
return nil if inv_collection.nil?

inv_collection.group
end

Expand Down
2 changes: 1 addition & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
module MrtDashboard
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 5.0
config.load_defaults 6.1

# Configuration for the application, engines, and railties goes here.
#
Expand Down
6 changes: 4 additions & 2 deletions config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ default: &default
# Merritt UI encountered 500 errors when mysql connections were no longer active.
# Jan 2024 - adding this setting to see if it prevents inactive connections.
# See https://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/ConnectionPool.html
idle_timeout: 0
#
# Oct 2024 - reverting this setting now that retry logic clears connections
# idle_timeout: 0
port: 3306
username: "{!SSM: inv/readwrite/db-user}"
password: "{!SSM: inv/readwrite/db-password}"
Expand All @@ -38,4 +40,4 @@ docker: &docker
username: user
password: password
encoding: utf8mb4
idle_timeout: 0
# idle_timeout: 0
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,6 @@
get('/presentations', to: redirect('https://github.com/CDLUC3/mrt-doc/blob/main/presentations/README.md'))
get('/wiki', to: redirect('https://github.com/CDLUC3/mrt-doc/wiki'))

# this method will be used to test retry failure handling
get('/force_fail' => 'object#force_fail')
end
11 changes: 9 additions & 2 deletions spec/controllers/owner_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,24 @@

@object_ark = objects[0].ark
@object = objects[0]
lid = InvLocalid.new(
@lid = InvLocalid.new(
local_id: @testlocalid,
inv_object: @object,
inv_owner: @object.inv_owner,
created: Time.now
)
lid.save!
@lid.save!

@client = mock_httpclient
end

after(:each) do
@lid.delete
@objects.each(&:delete)
@collection.delete
@owner.delete
end

def mock_owner_name(name)
allow_any_instance_of(ApplicationController).to receive(:current_owner_name).and_return(name)
end
Expand Down
16 changes: 16 additions & 0 deletions spec/features/collection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,22 @@
expect(page).to have_content(obj.erc_when)
end

# TODO: improve this test by having an actual filename to search
it 'find - search without wildcard' do
fill_in('terms', with: 'foozzz')
click_button 'Go'

expect(page).to have_content('There were no items that had the text matching')
end

# TODO: improve this test by having an actual filename to search
it 'find - search with wildcard' do
fill_in('terms', with: 'f*ozzz')
click_button 'Go'

expect(page).to have_content('There were no items that had the text matching')
end

it 'finds by arks' do
expected_objects = [1, 3, 5].map { |i| inv_objects[i] }
arks = expected_objects.map(&:ark)
Expand Down
1 change: 1 addition & 0 deletions spec/features/object_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
end

after(:each) do
@owner.delete
log_out!
end

Expand Down
Loading

0 comments on commit b22c306

Please sign in to comment.