Skip to content

Commit 8cd5409

Browse files
committed
skip n+1 on linkable images in content#edit
1 parent 6bab0f7 commit 8cd5409

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

app/controllers/content_controller.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ def edit
152152
return redirect_to @content, notice: t(:no_do_permission)
153153
end
154154

155+
@random_image_including_private_pool_cache = ImageUpload.where(
156+
user_id: current_user.id,
157+
).group_by { |image| [image.content_type, image.content_id] }
158+
155159
respond_to do |format|
156160
format.html { render 'content/edit', locals: { content: @content } }
157161
format.json { render json: @content }

app/views/content/form/field_types/_migration_link.html.erb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,13 @@
3030
)
3131
%>
3232
<% @linkables_raw.fetch(page_type.name, []).each do |linkable| %>
33+
<%
34+
linkable_image = @random_image_including_private_pool_cache.fetch([linkable.page_type, linkable.id], [])
35+
.sample
36+
.try(:src, :thumb) || asset_path("card-headers/#{linkable.page_type.downcase.pluralize}.jpg")
37+
%>
3338
<option value="<%= page_type %>-<%= linkable.id %>"
34-
data-icon="<%= asset_path linkable.random_image_including_private(format: :thumb) %>"
39+
data-icon="<%= asset_path linkable_image %>"
3540
<%= 'selected' if field[:value].include?("#{page_type}-#{linkable.id}") %>
3641
>
3742
<%= linkable.name %>

0 commit comments

Comments
 (0)