search: reduce queries in single tag searches (#4120).

Avoid some queries used in wiki page excerpts:

* Only try to load the artist if the tag is an artist tag.
* Avoid using `exists?` queries for wiki pages.
* Bugfix: don't show wiki excerpts for deleted wikis.
This commit is contained in:
evazion
2019-08-12 13:38:45 -05:00
parent bda69315ff
commit 14da425564
4 changed files with 11 additions and 31 deletions

View File

@@ -1,9 +1,5 @@
module PostSets module PostSets
class Base class Base
def has_wiki?
false
end
def raw def raw
false false
end end
@@ -12,10 +8,6 @@ module PostSets
nil nil
end end
def has_artist?
false
end
def artist def artist
nil nil
end end

View File

@@ -25,24 +25,14 @@ module PostSets
tag_array.reject {|tag| tag =~ /\Aorder:/i } tag_array.reject {|tag| tag =~ /\Aorder:/i }
end end
def has_wiki?
is_single_tag? && ::WikiPage.titled(tag_string).exists? && wiki_page.visible?
end
def has_wiki_text?
has_wiki? && wiki_page.body.present?
end
def has_blank_wiki? def has_blank_wiki?
is_simple_tag? && !has_wiki? tag.present? && !wiki_page.present?
end end
def wiki_page def wiki_page
if is_single_tag? return nil unless tag.present? && tag.wiki_page.present?
::WikiPage.titled(tag_string).first return nil unless !tag.wiki_page.is_deleted? && tag.wiki_page.visible?
else tag.wiki_page
nil
end
end end
def tag def tag
@@ -50,12 +40,10 @@ module PostSets
@tag ||= Tag.find_by(name: Tag.normalize_name(tag_string)) @tag ||= Tag.find_by(name: Tag.normalize_name(tag_string))
end end
def has_artist?
is_single_tag? && artist.present? && artist.visible?
end
def artist def artist
@artist ||= ::Artist.named(tag_string).active.first return nil unless tag.present? && tag.category == Tag.categories.artist
return nil unless tag.artist.present? && tag.artist.is_active? && tag.artist.visible?
tag.artist
end end
def pool_name def pool_name

View File

@@ -26,9 +26,9 @@
<menu id="post-sections"> <menu id="post-sections">
<li class="active"><a href="#" id="show-posts-link">Posts</a></li> <li class="active"><a href="#" id="show-posts-link">Posts</a></li>
<% if @post_set.has_artist? %> <% if @post_set.artist.present? %>
<li><%= link_to "Artist", artist_path(@post_set.artist), :id => "show-excerpt-link" %></li> <li><%= link_to "Artist", artist_path(@post_set.artist), :id => "show-excerpt-link" %></li>
<% elsif @post_set.has_wiki? %> <% elsif @post_set.wiki_page.present? %>
<li><%= link_to "Wiki", wiki_page_path(@post_set.wiki_page), :id => "show-excerpt-link" %></li> <li><%= link_to "Wiki", wiki_page_path(@post_set.wiki_page), :id => "show-excerpt-link" %></li>
<% elsif @post_set.has_pool? %> <% elsif @post_set.has_pool? %>
<li><%= link_to "Pool", pool_path(@post_set.pool), :id => "show-excerpt-link" %></li> <li><%= link_to "Pool", pool_path(@post_set.pool), :id => "show-excerpt-link" %></li>

View File

@@ -1,7 +1,7 @@
<%# post_set %> <%# post_set %>
<div id="excerpt" style="display: none;"> <div id="excerpt" style="display: none;">
<% if post_set.has_artist? %> <% if post_set.artist.present? %>
<% post_set.artist.tap do |artist| %> <% post_set.artist.tap do |artist| %>
<% if artist.visible? %> <% if artist.visible? %>
<% unless artist.notes.blank? %> <% unless artist.notes.blank? %>
@@ -21,7 +21,7 @@
</div> </div>
<% end %> <% end %>
<% end %> <% end %>
<% elsif post_set.has_wiki? %> <% elsif post_set.wiki_page.present? %>
<% post_set.wiki_page.tap do |wiki_page| %> <% post_set.wiki_page.tap do |wiki_page| %>
<div class="prose"> <div class="prose">
<% if wiki_page.other_names.present? %> <% if wiki_page.other_names.present? %>