Skip to content

Commit

Permalink
Merge pull request #5519 from avalonmediasystem/speedyaf_show
Browse files Browse the repository at this point in the history
Avoid expensive calls when rendering item show view page
  • Loading branch information
cjcolvar authored Dec 15, 2023
2 parents 75859b5 + 168f453 commit b42fc30
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
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

0 comments on commit b42fc30

Please sign in to comment.