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

pulibrary / imagecat-rails / e576dc1b-a4af-4fb9-bb3e-8c6dd404bed0

10 Oct 2023 07:50PM UTC coverage: 99.27% (+0.6%) from 98.63%
e576dc1b-a4af-4fb9-bb3e-8c6dd404bed0

Pull #189

circleci

hackartisan
simplify s3 command
Pull Request #189: Faster image load

26 of 26 new or added lines in 1 file covered. (100.0%)

136 of 137 relevant lines covered (99.27%)

27.61 hits per line

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

96.67
/app/services/card_image_loading_service.rb
1
# frozen_string_literal: true
2

3
require 'ruby-progressbar'
1✔
4
require 'ruby-progressbar/outputs/null'
1✔
5

6
# Class for card image loading service
7
class CardImageLoadingService
1✔
8
  attr_reader :logger, :suppress_progress
1✔
9

10
  def initialize(logger: nil, suppress_progress: false)
1✔
11
    @logger = logger || Logger.new($stdout)
1✔
12
    @suppress_progress = suppress_progress
1✔
13
  end
14

15
  def import
1✔
16
    (1..22).each { |disk| import_disk(disk) }
46✔
17
  end
18

19
  def import_disk(disk)
1✔
20
    logger.info("Fetching disk #{disk} file list")
44✔
21
    filenames = disk_array(disk)
44✔
22
    progress = progress_bar(filenames.count)
44✔
23
    filenames.each do |file_name|
44✔
24
      progress.increment
18✔
25
      find_or_create_card_image(file_name)
18✔
26
    end
27
  end
28

29
  private
1✔
30

31
  # returns something like
32
  # ["imagecat-disk9-0091-A3037-1358.0110.tif", "imagecat-disk9-0091-A3037-1358.0111.tif"]
33
  def disk_array(disk)
1✔
34
    s3_disk_list(disk).split("\n").map(&:split).map(&:last)
44✔
35
  end
36

37
  # returns something like
38
  # "2023-07-19 14:39:38       3422 imagecat-disk9-0091-A3037-1358.0110.tif\n2023-07-19 14:39:38       7010 imagecat-disk9-0091-A3037-1358.0111.tif\n"
39
  def s3_disk_list(disk)
1✔
40
    `aws s3 ls s3://puliiif-production/imagecat-disk#{disk}-`
×
41
  end
42

43
  def find_or_create_card_image(file_name)
1✔
44
    path = file_name.gsub('imagecat-disk', '').split('-')[0..-2].join('/')
18✔
45
    ci = CardImage.find_by(path: path, image_name: file_name)
18✔
46
    return if ci
18✔
47

48
    CardImage.create(path: path, image_name: file_name)
9✔
49
  end
50

51
  def progress_bar(total)
1✔
52
    ProgressBar.create(format: '%a %e %P% Loading: %c from %C', total: total, output: progress_output)
44✔
53
  end
54

55
  def progress_output
1✔
56
    ProgressBar::Outputs::Null if suppress_progress
44✔
57
  end
58
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