artists: reduce queries in artist summaries.

Avoid a few queries when searching for single artist tags.
This commit is contained in:
evazion
2019-09-05 00:00:15 -05:00
parent 416f817f6d
commit fc3b822bdf
3 changed files with 2 additions and 28 deletions

View File

@@ -386,14 +386,6 @@ class Artist < ApplicationRecord
end
module TagMethods
def has_tag_alias?
TagAlias.active.exists?(["antecedent_name = ?", name])
end
def tag_alias_name
TagAlias.active.find_by_antecedent_name(name).consequent_name
end
def category_name
Tag.category_for(name)
end

View File

@@ -3,16 +3,13 @@
<li><strong>Status</strong> <%= artist.status %></li>
<% if !artist.is_banned? || CurrentUser.is_member? %>
<% if artist.has_tag_alias? %>
<li><strong>Tag Alias</strong> <%= artist.tag_alias_name %></li>
<% end %>
<% if artist.other_names.present? %>
<li><strong>Other Names</strong> <%= link_to_artists(artist.other_names) %></li>
<% end %>
<% if artist.group_name.present? %>
<li><strong>Group</strong> <%= link_to_artist(artist.group_name) %></li>
<% end %>
<% if artist.members.any? %>
<% if artist.members.present? %>
<li><strong>Members</strong> <%= link_to_artists(artist.members.map(&:name)) %></li>
<% end %>
<% if artist.domains.any? %>
@@ -23,7 +20,7 @@
<% end %>
</ul>
<% end %>
<% if artist.urls.any? %>
<% if artist.urls.present? %>
<li><strong>URLs</strong></li>
<ul>
<% artist.urls.each do |url| %>

View File

@@ -64,21 +64,6 @@ class ArtistTest < ActiveSupport::TestCase
should_not allow_value("").for(:name)
end
context "with a matching tag alias" do
setup do
@tag_alias = FactoryBot.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
@artist = FactoryBot.create(:artist, :name => "aaa")
end
should "know it has an alias" do
assert_equal(true, @artist.has_tag_alias?)
end
should "know its alias" do
assert_equal("bbb", @artist.tag_alias_name)
end
end
context "that has been banned" do
setup do
@post = FactoryBot.create(:post, :tag_string => "aaa")