From a6106627b71c196ff63b8f6808c24fbd0fda72f2 Mon Sep 17 00:00:00 2001 From: Jeremy Friesen Date: Mon, 20 Nov 2023 13:28:40 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Skip=20derivative=20generation?= =?UTF-8?q?=20for=20thumbnails?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We're seeing jobs that are trying to find the HOCR of a thumbnail; we don't need that HOCR and it's spawning 5 jobs that are unecessary. Related to: - https://github.com/scientist-softserv/adventist-dl/issues/311 --- app/jobs/create_derivatives_job_decorator.rb | 10 +++++++--- spec/jobs/create_derivatives_job_decorator_spec.rb | 4 ++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/jobs/create_derivatives_job_decorator.rb b/app/jobs/create_derivatives_job_decorator.rb index 9df51ae9..28850284 100644 --- a/app/jobs/create_derivatives_job_decorator.rb +++ b/app/jobs/create_derivatives_job_decorator.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true -# OVERRIDE HYRAX 2.9.5 to conditionally skip derivative generation - +# OVERRIDE HYRAX 2.9.6 to conditionally skip derivative generation module CreateDerivativesJobDecorator # @note Override to include conditional validation def perform(file_set, file_id, filepath = nil) @@ -9,15 +8,20 @@ def perform(file_set, file_id, filepath = nil) super end + ## # @see https://github.com/scientist-softserv/adventist-dl/issues/311 for discussion on structure # of non-Archival PDF. NON_ARCHIVAL_PDF_SUFFIXES = [".reader.pdf", ".pdf-r.pdf"].freeze + ## + # We should not be creating derivatives for thumbnails. + FILE_SUFFIXES_TO_SKIP_DERIVATIVE_CREATION = ([".tn.jpg", ".tn.png"] + NON_ARCHIVAL_PDF_SUFFIXES).freeze + def self.create_derivative_for?(file_set:) # Our options appear to be `file_set.label` or `file_set.original_file.original_name`; in # favoring `#label` we are avoiding a call to Fedora. Is the label likely to be the original # file name? I hope so. - return false if NON_ARCHIVAL_PDF_SUFFIXES.any? { |suffix| file_set.label.downcase.end_with?(suffix) } + return false if FILE_SUFFIXES_TO_SKIP_DERIVATIVE_CREATION.any? { |suffix| file_set.label.downcase.end_with?(suffix) } true end diff --git a/spec/jobs/create_derivatives_job_decorator_spec.rb b/spec/jobs/create_derivatives_job_decorator_spec.rb index 04bef97e..bc54fa8f 100644 --- a/spec/jobs/create_derivatives_job_decorator_spec.rb +++ b/spec/jobs/create_derivatives_job_decorator_spec.rb @@ -12,8 +12,8 @@ let(:file_set) { double(FileSet, label: label) } - context 'when the file set is for a non-archival PDF' do - let(:label) { "my-non-archival#{described_class::NON_ARCHIVAL_PDF_SUFFIXES.first}" } + context 'when the file set is for a skipped suffix' do + let(:label) { "my-non-archival#{described_class::FILE_SUFFIXES_TO_SKIP_DERIVATIVE_CREATION.first}" } it { is_expected.to be_falsey } end