Skip to content

Commit f31b935

Browse files
authored
Merge pull request #6269 from avalonmediasystem/playlist_edit_speedup
Refactor to reduce solr requests needed to render playlist edit page
2 parents cbbbd8b + 3acfcdf commit f31b935

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

app/controllers/playlists_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ def manifest
247247
authorize! :read, @playlist
248248

249249
# Fetch all master files related to the playlist items in a single SpeedyAF::Base.where
250-
master_file_ids = @playlist.items.collect { |item| item.clip.master_file_id }
250+
master_file_ids = @playlist.clips.collect(&:master_file_id)
251251
master_files = []
252252
master_files = SpeedyAF::Proxy::MasterFile.where("id:#{master_file_ids.join(' id:')}", load_reflections: true) if master_file_ids.present?
253253
media_objects = master_files.collect(&:media_object).uniq(&:id)

app/models/playlist.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@ def valid_token?(token)
9999
access_token == token && visibility == Playlist::PRIVATE_WITH_TOKEN
100100
end
101101

102+
def clips_with_section_proxies
103+
cached_clips = clips.to_a
104+
section_ids = cached_clips.collect(&:master_file_id).uniq
105+
sections = SpeedyAF::Proxy::MasterFile.where("id:#{section_ids.join(' id:')}")
106+
cached_clips.map {|c| c.master_file = sections.find { |mf| mf.id == c.master_file_id }}
107+
cached_clips
108+
end
109+
102110
class << self
103111
# Find the i18n default playlist name
104112
def default_folder_name

app/views/playlists/_edit_form.html.erb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,22 @@ Unless required by applicable law or agreed to in writing, software distributed
7777
<%= form_for(@playlist, html: { id: 'playlist_sort_form', class: 'playlist_actions' }) do |fs| %>
7878
<div class="dd" data-playlist_id="<%= @playlist.id %>">
7979
<ol id="items" class="dd-list" style="list-style: none">
80+
<% clips = @playlist.clips_with_section_proxies %>
8081
<% @playlist.items.each_with_index do |i, index| %>
82+
<% clip = clips[index] %>
8183
<li class="container dd-item" data-id="<%= i.id %>">
8284
<div class="row">
8385
<div class="col-sm-2">
8486
<span class="fa fa-arrows-v float-left dd-handle"></span>
8587
<%= text_field_tag "playlist[items_attributes[#{index}[position]]]", i.position, class: 'form-control position-input', form: 'playlist_sort_form' %>
8688
<%= hidden_field_tag "playlist[items_attributes[#{index}[id]]]", i.id, form: 'playlist_sort_form' %>
8789
</div>
88-
<% if can? :read, i.clip.master_file %>
90+
<% if can? :read, clip.master_file %>
8991
<div class="col-sm-8 title" style="margin-top:5px">
90-
<%= link_to i.clip.title, i.clip.mediafragment_uri, id: "playlist_item_title_label_#{i.id}" %>
92+
<%= link_to clip.title, clip.mediafragment_uri, id: "playlist_item_title_label_#{i.id}" %>
9193
</div>
9294
<div class="col-sm-2 text-right" style="margin-top:5px">
93-
<button id="playlist_item_edit_button" class="btn btn-sm fa fa-edit" <%= i.clip.master_file.nil? ? 'disabled' : '' %>
95+
<button id="playlist_item_edit_button" class="btn btn-sm fa fa-edit" <%= clip.master_file.nil? ? 'disabled' : '' %>
9496
data-toggle="collapse" href="#playlist_item_edit_<%= i.id %>" aria-expanded="false" type="button">
9597
</button>
9698
<label>
@@ -100,12 +102,12 @@ Unless required by applicable law or agreed to in writing, software distributed
100102
</div>
101103
<% else %>
102104
<div class="col-sm-9 title" style="margin-top:5px">
103-
<% if i.clip.master_file.nil? %>
105+
<% if clip.master_file.nil? %>
104106
<i class="fa fa-times-circle" title="The source for this item has been deleted"></i>
105107
<span class="playlist_item_denied">[deleted item]</span>
106108
<% else %>
107109
<i class="fa fa-lock" title="You don't have permission to view this item"></i>
108-
<span class="playlist_item_denied">[inaccessible item] <%= i.clip.master_file.media_object.id %></span>
110+
<span class="playlist_item_denied">[inaccessible item] <%= clip.master_file.media_object_id %></span>
109111
<% end %>
110112
</div>
111113
<div class="col-sm-1 form-check text-right">
@@ -273,4 +275,4 @@ Unless required by applicable law or agreed to in writing, software distributed
273275
});
274276
</script>
275277
276-
<% end %>
278+
<% end %>

0 commit comments

Comments
 (0)