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

Commit

Permalink
🎁 Only run thumbnail derivatives on thumbnails
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kirkkwang committed Nov 29, 2023
1 parent c89ad7c commit 358d694
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 5 deletions.
3 changes: 1 addition & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,14 @@ GIT

GIT
remote: https://github.com/scientist-softserv/iiif_print.git
revision: e42cfd2a6d9b0aac9901084625ee1e1a0a3ccb6d
revision: 5c5fa6880b3dc22beed738cfcba7af57b698ac36
branch: main
specs:
iiif_print (1.0.0)
blacklight_iiif_search (>= 1.0, < 3.0)
derivative-rodeo (~> 0.5)
hyrax (>= 2.5, < 6)
nokogiri (>= 1.13.2)
rails (>= 5.0, < 8.0)
rdf-vocab (~> 3.0)

GIT
Expand Down
9 changes: 9 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ class Application < Rails::Application
Rails.configuration.cache_classes ? require(c) : load(c)
end

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

# resolve reloading issue in dev mode
Expand All @@ -121,4 +128,6 @@ class Application < Rails::Application
# copies tinymce assets directly into public/assets
config.tinymce.install = :copy
end

THUMBNAIL_FILE_SUFFIX = '.tn.jpg'
end
2 changes: 2 additions & 0 deletions config/initializers/iiif_print.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,6 @@
if ENV.fetch('LOCAL_RODEO_LOG', 'false') == 'true'
FileUtils.mkdir_p(Rails.root.join('log').to_s)
DerivativeRodeo.config.logger = Logger.new(Rails.root.join("log/dr.log").to_s, level: Logger::DEBUG)
else
DerivativeRodeo.config.logger = Rails.logger
end
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
module IIIFManifest
module ManifestBuilderDecorator
module CanvasBuilderFactoryDecorator
THUMBNAIL_FILE_SUFFIX = '.tn.jpg'

def from(work)
composite_builder.new(
*file_set_presenters(work).map do |presenter|
next if presenter.label.downcase.end_with?(THUMBNAIL_FILE_SUFFIX) || !presenter.image?
next if presenter.label.downcase.end_with?(Hyku::THUMBNAIL_FILE_SUFFIX) || !presenter.image?
canvas_builder_factory.new(presenter, work)
end
)
Expand Down
28 changes: 28 additions & 0 deletions spec/config/application_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

RSpec.describe 'config/application.rb' do
describe 'IiifPrint::DerivativeRodeoService.named_derivatives_and_generators_filter' do
subject { IiifPrint::DerivativeRodeoService.named_derivatives_and_generators_filter.call(file_set: file_set, filename: filename, named_derivatives_and_generators: named_derivatives_and_generators).keys }

let(:file_set) { double('file_set') }
let(:named_derivatives_and_generators) do
IiifPrint::DerivativeRodeoService.named_derivatives_and_generators_by_type.fetch(:image).deep_dup
end

context 'for a thumbnail file' do
let(:filename) { 'image.TN.jpg' }

it 'will only generate a thumbnail' do
expect(subject).to eq [:thumbnail]
end
end

context 'for a non-thumbnail file' do
let(:filename) { 'image.jpg' }

it 'will generate all derivatives' do
expect(subject).to eq [:thumbnail, :json, :xml, :txt]
end
end
end
end

0 comments on commit 358d694

Please sign in to comment.