Skip to content

Commit 8552b17

Browse files
authored
Hotfix - reindex work versions after thumbnail generation (#1889)
* Reindex work versions in thumbnail job if uploaded file is not a thumbnail upload (ie autogenerated) * Niftany * fix thumbnail upload index update condition
1 parent 7630937 commit 8552b17

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

app/jobs/shrine/thumbnail_job.rb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,16 @@ def perform(record)
99
attacher.create_derivatives :thumbnail
1010
record.save
1111
end
12-
# If the created record is a thumbnail uploaded by a user,
13-
# then the associated resource needs to be reindexed
14-
record.thumbnail_upload.resource.update_index if record.thumbnail_upload.present?
12+
13+
if record.thumbnail_upload.present?
14+
# If the created record is a thumbnail uploaded by a user,
15+
# then the associated resource needs to be reindexed
16+
record.thumbnail_upload.resource.update_index
17+
else
18+
# Update WorkVersions' solr docs with thumbnail url when
19+
# thumbnail is auto-generated from a WorkVersion upload
20+
record.work_versions.each(&:update_index)
21+
end
1522
rescue Shrine::AttachmentChanged, ActiveRecord::RecordNotFound
1623
# attachment has changed or record has been deleted, nothing to do
1724
end

spec/jobs/shrine/thumbnail_job_spec.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,27 @@
2222
described_class.perform_now(image_record)
2323
expect(image_record.file_attacher.url(:thumbnail)).to include('thumbnails')
2424
end
25+
26+
it 'reindexes associated work versions when no thumbnail upload is present' do
27+
work_version_one = instance_spy(WorkVersion)
28+
work_version_two = instance_spy(WorkVersion)
29+
allow(pdf_record).to receive_messages(work_versions: [work_version_one, work_version_two], thumbnail_upload: nil)
30+
31+
described_class.perform_now(pdf_record)
32+
33+
expect(work_version_one).to have_received(:update_index)
34+
expect(work_version_two).to have_received(:update_index)
35+
end
36+
37+
it 'reindexes associated thumbnail upload resource when present' do
38+
thumbnail_upload = create(:thumbnail_upload)
39+
resource = thumbnail_upload.resource
40+
allow(resource).to receive(:update_index)
41+
allow(pdf_record).to receive_messages(work_versions: [], thumbnail_upload: thumbnail_upload)
42+
43+
described_class.perform_now(pdf_record)
44+
45+
expect(resource).to have_received(:update_index)
46+
end
2547
end
2648
end

0 commit comments

Comments
 (0)