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

backport: delegate IIIF Manifest cache key version to presenter #4419

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
6 changes: 1 addition & 5 deletions app/services/hyrax/caching_iiif_manifest_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,9 @@ def manifest_cache_key(presenter:)
end

##
# @note `etag` is a better option than the solr document `_version_`; the
# latter isn't always available, depending on how the presenter was
# built!
#
# @return [String]
def version_for(presenter)
presenter.etag
presenter.version
Copy link
Contributor

Choose a reason for hiding this comment

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

I like this explicit method name usage; Instead of relying on an implicit understanding of etag (which is reasonable but just a bit less clear).

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 @@ -170,5 +170,21 @@
end
end
end

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

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

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

it 'is still a string' do
expect(presenter.version).to be_a String
end
end
end
end
# rubocop:enable 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