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

Improve thumbnail load times #6032

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
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
11 changes: 8 additions & 3 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def image_for(document)

if master_file_id
if video_count > 0
thumbnail_master_file_path(master_file_id)
document["sections"][:docs].first["thumbnail"][:docs].first["content_ss"]
elsif audio_count > 0
asset_path('audio_icon.png')
else
Expand All @@ -86,9 +86,14 @@ def image_for(document)
end

def avalon_image_tag(document, image_options)
image_url = image_for(document)
image = image_for(document)
link_to(media_object_path(document[:id]), {class: 'result-thumbnail'}) do
image_url.present? ? image_tag(image_url) : image_tag('no_icon.png')
return image_tag('no_icon.png') unless image.present?
if image.start_with?(root_url)
image_tag(image)
else
image_tag("data:image/jpg;base64,#{image}")
end
end
end

Expand Down
3 changes: 2 additions & 1 deletion app/models/indexed_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ def to_solr(solr_doc = {}, opts = {})
return solr_doc unless opts[:external_index]
solr_doc.tap do |doc|
doc[:id] = id
doc[:isPartOf_ssi] = id.gsub(/\/.*/, '')
doc[:has_model_ssim] = self.class.name
doc[:uri_ss] = uri.to_s
doc[:mime_type_ss] = mime_type
doc[:original_name_ss] = original_name
doc[:original_name_ssi] = original_name
doc[:size_is] = content.present? ? content.size : 0
doc[:'empty?_bs'] = content.blank?
if index_content?
Expand Down
10 changes: 9 additions & 1 deletion app/models/search_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def term_frequency_counts(solr_parameters)
transcripts_present = SupplementalFile.with_tag('transcript').any?

# List of fields for displaying on search results (Blacklight index fields)
fl = ['id', 'has_model_ssim', 'title_tesi', 'date_issued_ssi', 'creator_ssim', 'abstract_ssi', 'duration_ssi', 'section_id_ssim', 'avalon_resource_type_ssim']
fl = ['id', 'has_model_ssim', 'title_tesi', 'date_issued_ssi', 'creator_ssim', 'abstract_ssi', 'duration_ssi', 'section_id_ssim', 'avalon_resource_type_ssim', 'content_ss']

# Add a field for matching child sections
fl << "sections:[subquery]"
Expand All @@ -81,11 +81,19 @@ def term_frequency_counts(solr_parameters)
fl << "metadata_tf_#{i}:termfreq(mods_tesim,#{RSolr.solr_escape(term)})"
fl << "structure_tf_#{i}:termfreq(section_label_tesim,#{RSolr.solr_escape(term)})"
fl << "transcript_tf_#{i}" if transcripts_present
fl << "thumbnail"
sections_fl << "transcript_tf_#{i}" if transcripts_present
transcripts_fl << "transcript_tf_#{i}:termfreq(transcript_tsim,#{RSolr.solr_escape(term)})" if transcripts_present
sections_fl << "thumbnail:[subquery]"
end
solr_parameters[:fl] = fl.join(',')

solr_parameters["sections.thumbnail.q"] = "{!terms f=isPartOf_ssi v=$row.id}{!join to=id from=isPartOf_ssim}"
solr_parameters["sections.thumbnail.fq"] = "original_name_ssi:thumbnail.jpg"
solr_parameters["sections.thumbnail.defType"] = "lucene"
solr_parameters["sections.thumbnail.rows"] = 1
solr_parameters["sections.thumbnail.fl"] = "content_ss"

return solr_parameters unless transcripts_present
sections_fl << "transcripts:[subquery]"
solr_parameters["sections.fl"] = sections_fl.join(',')
Expand Down
8 changes: 6 additions & 2 deletions app/views/catalog/_thumbnail_media_object.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ Unless required by applicable law or agreed to in writing, software distributed
%>

<div class="col-md-12 col-lg-4 row">
<% if image_url = image_for(document) %>
<% if image = image_for(document) %>
<%= link_to(media_object_path(document[:id]), aria: { hidden: 'true'}, tabindex: -1, class: 'result-thumbnail') do %>
<%= image_tag( image_url, alt: "" ) %>
<% if image.start_with?(root_url) %>
<%= image_tag( image, alt: "") %>
<% else %>
<%= image_tag( "data:image/jpg;base64,#{image}", alt: "" ) %>
<% end %>
<% end %>
<% else %>
<%= image_tag 'no_icon.png', alt: "", class: 'result-thumbnail no-icon' %>
Expand Down