Skip to content

Commit

Permalink
Memoize to avoid making many expensive solr calls
Browse files Browse the repository at this point in the history
  • Loading branch information
cjcolvar committed Dec 12, 2023
1 parent 8cfe54b commit 168f453
Showing 1 changed file with 5 additions and 5 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

0 comments on commit 168f453

Please sign in to comment.