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

Avoid expensive calls when rendering item show view page #5519

Merged
merged 2 commits into from
Dec 15, 2023
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: 5 additions & 5 deletions app/presenters/speedy_af/proxy/media_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,15 @@ def master_files
# This is important otherwise speedy_af will reify from fedora when trying to access this field.
# When adding a new property to the master file model that will be used in the interface,
# add it to the default below to avoid reifying for master files lacking a value for the property.
SpeedyAF::Proxy::MasterFile.where("isPartOf_ssim:#{id}",
order: -> { master_file_ids },
load_reflections: true)
@master_files ||= SpeedyAF::Proxy::MasterFile.where("isPartOf_ssim:#{id}",
order: -> { master_file_ids },
load_reflections: true)
end
alias_method :indexed_master_files, :master_files
alias_method :ordered_master_files, :master_files

def collection
SpeedyAF::Proxy::Admin::Collection.find(collection_id)
@collection ||= SpeedyAF::Proxy::Admin::Collection.find(collection_id)
end

def lending_period
Expand Down Expand Up @@ -149,7 +149,7 @@ def language
end

def sections_with_files(tag: '*')
ordered_master_file_ids.select { |m| SpeedyAF::Proxy::MasterFile.find(m).supplemental_files(tag: tag).present? }
master_files.select { |master_file| master_file.supplemental_files(tag: tag).present? }
end

protected
Expand Down
7 changes: 4 additions & 3 deletions app/views/media_objects/_share.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,18 @@ Unless required by applicable law or agreed to in writing, software distributed
<script>
let canvasIndex = 0;
$(document).ready(function() {
const mediaObject = <%= @media_object.to_json.html_safe %>;
const mediaObjectId = <% @media_object.id %>
const sectionIds = <%= @media_object.ordered_master_file_ids.to_json.html_safe %>;
const event = new CustomEvent('canvasswitch', { detail: { lti_share_link: '', link_back_url: '', embed_code: '' } })
function canvasIndexListener() {
let player = document.getElementById('iiif-media-player');
if (player && player.player != undefined) {
player.player.on("loadedmetadata", () => {
if (player.dataset.canvasindex != canvasIndex) {
canvasIndex = parseInt(player.dataset.canvasindex);
const sectionId = mediaObject.files[canvasIndex].id;
const sectionId = sectionIds[canvasIndex];
$.ajax({
url: '/media_objects/' + mediaObject.id + '/section/' + sectionId + '/stream',
url: '/media_objects/' + mediaObjectId + '/section/' + sectionId + '/stream',
type: 'GET',
success: function(data) {
event.detail.lti_share_link = data.lti_share_link;
Expand Down