mirror of
https://github.com/indentlabs/notebook.git
synced 2025-10-26 11:19:22 +00:00
skip n+1 on linkable images in content#edit
This commit is contained in:
parent
6bab0f705b
commit
8cd54092ce
@ -152,6 +152,10 @@ class ContentController < ApplicationController
|
||||
return redirect_to @content, notice: t(:no_do_permission)
|
||||
end
|
||||
|
||||
@random_image_including_private_pool_cache = ImageUpload.where(
|
||||
user_id: current_user.id,
|
||||
).group_by { |image| [image.content_type, image.content_id] }
|
||||
|
||||
respond_to do |format|
|
||||
format.html { render 'content/edit', locals: { content: @content } }
|
||||
format.json { render json: @content }
|
||||
|
||||
@ -30,8 +30,13 @@
|
||||
)
|
||||
%>
|
||||
<% @linkables_raw.fetch(page_type.name, []).each do |linkable| %>
|
||||
<%
|
||||
linkable_image = @random_image_including_private_pool_cache.fetch([linkable.page_type, linkable.id], [])
|
||||
.sample
|
||||
.try(:src, :thumb) || asset_path("card-headers/#{linkable.page_type.downcase.pluralize}.jpg")
|
||||
%>
|
||||
<option value="<%= page_type %>-<%= linkable.id %>"
|
||||
data-icon="<%= asset_path linkable.random_image_including_private(format: :thumb) %>"
|
||||
data-icon="<%= asset_path linkable_image %>"
|
||||
<%= 'selected' if field[:value].include?("#{page_type}-#{linkable.id}") %>
|
||||
>
|
||||
<%= linkable.name %>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user