From 14da425564ffd0af47fb51157f1ac7812c7a03eb Mon Sep 17 00:00:00 2001 From: evazion Date: Mon, 12 Aug 2019 13:38:45 -0500 Subject: [PATCH] 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. --- app/logical/post_sets/base.rb | 8 ------ app/logical/post_sets/post.rb | 26 +++++-------------- app/views/posts/index.html.erb | 4 +-- .../posts/partials/index/_excerpt.html.erb | 4 +-- 4 files changed, 11 insertions(+), 31 deletions(-) diff --git a/app/logical/post_sets/base.rb b/app/logical/post_sets/base.rb index 0b5a335c3..4f49bb05c 100644 --- a/app/logical/post_sets/base.rb +++ b/app/logical/post_sets/base.rb @@ -1,9 +1,5 @@ module PostSets class Base - def has_wiki? - false - end - def raw false end @@ -12,10 +8,6 @@ module PostSets nil end - def has_artist? - false - end - def artist nil end diff --git a/app/logical/post_sets/post.rb b/app/logical/post_sets/post.rb index 6e8c75193..ec92c6270 100644 --- a/app/logical/post_sets/post.rb +++ b/app/logical/post_sets/post.rb @@ -25,24 +25,14 @@ module PostSets tag_array.reject {|tag| tag =~ /\Aorder:/i } 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? - is_simple_tag? && !has_wiki? + tag.present? && !wiki_page.present? end def wiki_page - if is_single_tag? - ::WikiPage.titled(tag_string).first - else - nil - end + return nil unless tag.present? && tag.wiki_page.present? + return nil unless !tag.wiki_page.is_deleted? && tag.wiki_page.visible? + tag.wiki_page end def tag @@ -50,12 +40,10 @@ module PostSets @tag ||= Tag.find_by(name: Tag.normalize_name(tag_string)) end - def has_artist? - is_single_tag? && artist.present? && artist.visible? - end - 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 def pool_name diff --git a/app/views/posts/index.html.erb b/app/views/posts/index.html.erb index 3630775ae..114a2d842 100644 --- a/app/views/posts/index.html.erb +++ b/app/views/posts/index.html.erb @@ -26,9 +26,9 @@
  • Posts
  • - <% if @post_set.has_artist? %> + <% if @post_set.artist.present? %>
  • <%= link_to "Artist", artist_path(@post_set.artist), :id => "show-excerpt-link" %>
  • - <% elsif @post_set.has_wiki? %> + <% elsif @post_set.wiki_page.present? %>
  • <%= link_to "Wiki", wiki_page_path(@post_set.wiki_page), :id => "show-excerpt-link" %>
  • <% elsif @post_set.has_pool? %>
  • <%= link_to "Pool", pool_path(@post_set.pool), :id => "show-excerpt-link" %>
  • diff --git a/app/views/posts/partials/index/_excerpt.html.erb b/app/views/posts/partials/index/_excerpt.html.erb index f6340caa6..ae5487793 100644 --- a/app/views/posts/partials/index/_excerpt.html.erb +++ b/app/views/posts/partials/index/_excerpt.html.erb @@ -1,7 +1,7 @@ <%# post_set %> <% end %> <% end %> - <% elsif post_set.has_wiki? %> + <% elsif post_set.wiki_page.present? %> <% post_set.wiki_page.tap do |wiki_page| %>
    <% if wiki_page.other_names.present? %>