ai tags: fix N+1 query issue.
This commit is contained in:
@@ -10,7 +10,7 @@ class AITagsController < ApplicationController
|
||||
params[:search][:is_posted] ||= "true" if request.format.html?
|
||||
|
||||
@ai_tags = authorize AITag.visible(CurrentUser.user).paginated_search(params, limit: limit, count_pages: false)
|
||||
@ai_tags = @ai_tags.includes(:media_asset, :tag, :post) if request.format.html?
|
||||
@ai_tags = @ai_tags.includes(:tag, media_asset: :post) if request.format.html?
|
||||
|
||||
respond_with(@ai_tags)
|
||||
end
|
||||
|
||||
@@ -47,12 +47,12 @@ class AITag < ApplicationRecord
|
||||
|
||||
# True if the AI tag is present on the post; false if the AI tag is not on the post, or the asset isn't a post yet.
|
||||
def post_tagged?
|
||||
if post.nil?
|
||||
if media_asset.post.nil?
|
||||
false
|
||||
elsif tag.name =~ /\Arating:(.)\z/
|
||||
post.rating == $1
|
||||
media_asset.post.rating == $1
|
||||
else
|
||||
post.has_tag?(tag.name)
|
||||
media_asset.post.has_tag?(tag.name)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -3,10 +3,11 @@
|
||||
<div class="text-center text-xs leading-none px-2 w-full mt-2">
|
||||
<div class="truncate mb-2">
|
||||
<%= link_to "#{ai_tag.tag.pretty_name}", ai_tags_path(search: search_params.merge(tag_name: ai_tag.tag.name)), class: "tag-type-#{ai_tag.tag.category}", "data-tag-name": ai_tag.tag.name, title: ai_tag.tag.pretty_name %>
|
||||
<%= link_to "#{ai_tag.score}%", ai_tags_path(search: search_params.merge(tag_name: ai_tag.tag.name, score: ">=#{ai_tag.score}")), class: "block tag-type-#{ai_tag.tag.category}", "data-tag-name": ai_tag.tag.name %>
|
||||
<br>
|
||||
<%= link_to "#{ai_tag.score}%", ai_tags_path(search: search_params.merge(tag_name: ai_tag.tag.name, score: ">=#{ai_tag.score}")), class: "tag-type-#{ai_tag.tag.category}", "data-tag-name": ai_tag.tag.name %>
|
||||
</div>
|
||||
|
||||
<% if ai_tag.post.nil? || !policy(ai_tag).update? %>
|
||||
<% if media_asset.post.nil? || !policy(ai_tag).update? %>
|
||||
<%= button_to "Add", nil, class: "button-primary button-sm", disabled: true %>
|
||||
<% elsif ai_tag.post_tagged? %>
|
||||
<%= button_to "Remove", tag_ai_tag_path(media_asset_id: ai_tag.media_asset, tag_id: ai_tag.tag), remote: true, method: :put, params: { mode: "remove" }, class: "button-outline-danger button-sm", title: "Remove the tag from the post" %>
|
||||
|
||||
Reference in New Issue
Block a user