Skip to content
This repository was archived by the owner on Oct 24, 2024. It is now read-only.

Commit aab7d39

Browse files
author
Kirk Wang
committed
🎁 Only run thumbnail derivatives on thumbnails
We were seeing that our thumbnail files were getting word coordinates derivatives, which is a waste of processing time. The jobs would eventually fail but ideally we don't want them to run at all for thumbnails. This commit will upgrade to the latest version of IIIF Print where a new configurable class attribute has been added to enable a more granular control over which derivatives are run on what files. Also in this commit, we were seeing a nilClass error for a logger in development, so that has also been fixed. Ref: - https://github.com/scientist-softserv/adventist-dl/issues/676 - notch8/iiif_print#306
1 parent c89ad7c commit aab7d39

File tree

5 files changed

+49
-5
lines changed

5 files changed

+49
-5
lines changed

Gemfile.lock

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,14 @@ GIT
3131

3232
GIT
3333
remote: https://github.com/scientist-softserv/iiif_print.git
34-
revision: e42cfd2a6d9b0aac9901084625ee1e1a0a3ccb6d
34+
revision: 5c5fa6880b3dc22beed738cfcba7af57b698ac36
3535
branch: main
3636
specs:
3737
iiif_print (1.0.0)
3838
blacklight_iiif_search (>= 1.0, < 3.0)
3939
derivative-rodeo (~> 0.5)
4040
hyrax (>= 2.5, < 6)
4141
nokogiri (>= 1.13.2)
42-
rails (>= 5.0, < 8.0)
4342
rdf-vocab (~> 3.0)
4443

4544
GIT

config/application.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ class Application < Rails::Application
9696
Rails.configuration.cache_classes ? require(c) : load(c)
9797
end
9898

99+
# See: https://github.com/scientist-softserv/adventist-dl/issues/676
100+
IiifPrint::DerivativeRodeoService.named_derivatives_and_generators_filter =
101+
->(file_set:, filename:, named_derivatives_and_generators:) do
102+
named_derivatives_and_generators.reject do |named_derivative, generators|
103+
named_derivative != :thumbnail && filename.downcase.ends_with?(Hyku::THUMBNAIL_FILE_SUFFIX)
104+
end
105+
end
99106
end
100107

101108
# resolve reloading issue in dev mode
@@ -121,4 +128,6 @@ class Application < Rails::Application
121128
# copies tinymce assets directly into public/assets
122129
config.tinymce.install = :copy
123130
end
131+
132+
THUMBNAIL_FILE_SUFFIX = '.tn.jpg'
124133
end

config/initializers/iiif_print.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,6 @@
127127
if ENV.fetch('LOCAL_RODEO_LOG', 'false') == 'true'
128128
FileUtils.mkdir_p(Rails.root.join('log').to_s)
129129
DerivativeRodeo.config.logger = Logger.new(Rails.root.join("log/dr.log").to_s, level: Logger::DEBUG)
130+
else
131+
DerivativeRodeo.config.logger = Rails.logger
130132
end

lib/iiif_manifest/manifest_builder/canvas_builder_factory_decorator.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@
55
module IIIFManifest
66
module ManifestBuilderDecorator
77
module CanvasBuilderFactoryDecorator
8-
THUMBNAIL_FILE_SUFFIX = '.tn.jpg'
9-
108
def from(work)
119
composite_builder.new(
1210
*file_set_presenters(work).map do |presenter|
13-
next if presenter.label.downcase.end_with?(THUMBNAIL_FILE_SUFFIX) || !presenter.image?
11+
next if presenter.label.downcase.end_with?(Hyku::THUMBNAIL_FILE_SUFFIX) || !presenter.image?
1412
canvas_builder_factory.new(presenter, work)
1513
end
1614
)

spec/config/application_spec.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# frozen_string_literal: true
2+
3+
# rubocop:disable RSpec/DescribeClass
4+
RSpec.describe 'config/application.rb' do
5+
# rubocop:enable RSpec/DescribeClass
6+
describe 'IiifPrint::DerivativeRodeoService.named_derivatives_and_generators_filter' do
7+
subject do
8+
IiifPrint::DerivativeRodeoService
9+
.named_derivatives_and_generators_filter
10+
.call(file_set: file_set,
11+
filename: filename,
12+
named_derivatives_and_generators: named_derivatives_and_generators).keys
13+
end
14+
15+
let(:file_set) { double('file_set') }
16+
let(:named_derivatives_and_generators) do
17+
IiifPrint::DerivativeRodeoService.named_derivatives_and_generators_by_type.fetch(:image).deep_dup
18+
end
19+
20+
context 'for a thumbnail file' do
21+
let(:filename) { 'image.TN.jpg' }
22+
23+
it 'will only generate a thumbnail' do
24+
expect(subject).to eq [:thumbnail]
25+
end
26+
end
27+
28+
context 'for a non-thumbnail file' do
29+
let(:filename) { 'image.jpg' }
30+
31+
it 'will generate all derivatives' do
32+
expect(subject).to eq %i[thumbnail json xml txt]
33+
end
34+
end
35+
end
36+
end

0 commit comments

Comments
 (0)