• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pulibrary / allsearch_api / 55f37a69-f198-45d6-96dc-4272aa3cb82c

02 Dec 2025 04:55PM UTC coverage: 99.904% (+0.001%) from 99.903%
55f37a69-f198-45d6-96dc-4272aa3cb82c

Pull #415

circleci

sandbergja
Remove ActiveRecord-based LibraryDatabaseRecord class

This also improves the performance of loading Library Database metadata from Lib-jobs
by combining all creation into a single INSERT query, rather than running an INSERT
for each row in the CSV.

To confirm, I ran this benchmark before deleting the LibraryDatabaseRecord class:

```
Benchmark.ips do |b|
  library_database_repo = LibraryDatabaseRepository.new Rails.application.config.rom
  csv = CSV.read Rails.root.join('spec/fixtures/files/libjobs/library-databases.csv'), headers: true
  b.report('LibraryDatabaseRecord::new_from_csv') do
    csv.each { LibraryDatabaseRecord.new_from_csv(it)}
    library_database_repo.delete
  end

  b.report('LibraryDatabaseRepository#create_from_csv') do
    library_database_repo.create_from_csv csv
    library_database_repo.delete
  end

  b.compare!
end
```

Results:

```
Warming up --------------------------------------
LibraryDatabaseRecord::new_from_csv
                         3.000 i/100ms
LibraryDatabaseRepository#create_from_csv
                        10.000 i/100ms
Calculating -------------------------------------
LibraryDatabaseRecord::new_from_csv
                         28.764 (±27.8%) i/s   (34.77 ms/i) -    135.000 in   5.004122s
LibraryDatabaseRepository#create_from_csv
                        116.179 (±18.9%) i/s    (8.61 ms/i) -    560.000 in   5.031764s

Comparison:
LibraryDatabaseRepository#create_from_csv:      116.2 i/s
LibraryDatabaseRecord::new_from_csv:       28.8 i/s - 4.04x  slower
```

Closes #402
Pull Request #415: Remove ActiveRecord-based LibraryDatabaseRecord class

14 of 14 new or added lines in 2 files covered. (100.0%)

20 existing lines in 4 files now uncovered.

1040 of 1041 relevant lines covered (99.9%)

104.28 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/app/models/art_museum.rb
1
# frozen_string_literal: true
2

3
# This class is responsible for querying the Art Museum API
4
class ArtMuseum
3✔
5
  include ActiveModel::API
3✔
6
  include Parsed
3✔
7

8
  attr_reader :service, :service_response
3✔
9

10
  def initialize(query_terms:)
3✔
11
    @query_terms = query_terms
16✔
12
    @service = 'artmuseum'
16✔
13
    @service_response = art_museum_service_response
16✔
14
  end
15

16
  def query_terms
3✔
17
    @query_terms.truncate(220, omission: '', separator: /\s/)
44✔
18
  end
19

20
  private
3✔
21

22
  def art_museum_service_response
3✔
23
    uri = URI::HTTPS.build(host: 'data.artmuseum.princeton.edu', path: '/search',
16✔
24
                           query: "q=#{query_terms}&type=all&size=3")
25
    response = Net::HTTP.get(uri)
16✔
26
    begin
27
      JSON.parse(response, symbolize_names: true)
16✔
28
    rescue JSON::ParserError
29
      handle_parser_error response
1✔
30
    end
31
  end
32

33
  def number
3✔
UNCOV
34
    service_response.dig(:hits, :total)
14✔
35
  end
36

37
  def more_link
3✔
UNCOV
38
    URI::HTTPS.build(host: 'artmuseum.princeton.edu', path: '/search/collections',
28✔
39
                     query: "mainSearch=\"#{query_terms}\"")
40
  end
41

42
  def documents
3✔
UNCOV
43
    @documents ||= service_response.dig(:hits, :hits)
14✔
44
  end
45

46
  def handle_parser_error(response)
3✔
47
    raise AllsearchError.new(
1✔
48
      problem: 'UPSTREAM_ERROR',
49
      msg: "Query to upstream failed with #{ActionController::Base.helpers.strip_tags(response)}"
50
    )
51
  end
52
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc