Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

delegate IIIF Manifest cache key version to presenter #4418

Merged
merged 1 commit into from
Jul 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions app/presenters/hyrax/iiif_manifest_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,16 @@ def work_presenters
member_presenters.select(&:work?)
end

##
# @note ideally, this value will be cheap to retrieve, and will reliably
# change any time the manifest JSON will change. the current implementation
# is more blunt than this, changing only when the work itself changes.
#
# @return [String] a string tag suitable for cache keys for this manifiest
def version
object.try(:modified_date)&.to_s || ''
end

##
# An Ability-like object that gives `true` for all `can?` requests
class NullAbility
Expand Down
2 changes: 1 addition & 1 deletion app/services/hyrax/caching_iiif_manifest_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def manifest_cache_key(presenter:)
#
# @return [String]
def version_for(presenter)
presenter.etag
presenter.version
end
end
end
16 changes: 16 additions & 0 deletions spec/presenters/hyrax/iiif_manifest_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,5 +209,21 @@
end
end
end

describe '#version' do
let(:work) { create(:work) }

it 'returns a string' do
expect(presenter.version).to be_a String
end

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worthwhile to add a test here showing that it updates when the work updates? Maybe something like this?

it 'changes when the work changes' do
  expect { work.save }.to change { presenter.version }
end

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a PR for this spec. If @no-reply likes it, we'll add it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see discussion at #4421 (review)

context 'when the work is unsaved' do
let(:work) { build(:monograph) }

it 'is still a string' do
expect(presenter.version).to be_a String
end
end
end
end
# rubocop:enable Style/BracesAroundHashParameters
2 changes: 1 addition & 1 deletion spec/services/hyrax/caching_iiif_manifest_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
double(
'Presenter',
id: id,
etag: etag,
version: etag,
work_presenters: [work_presenter],
manifest_url: manifest_url,
description: ["A Treatise on Coding in Samvera"],
Expand Down