artists: reduce queries in artist summaries.
Avoid a few queries when searching for single artist tags.
This commit is contained in:
@@ -386,14 +386,6 @@ class Artist < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
module TagMethods
|
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
|
def category_name
|
||||||
Tag.category_for(name)
|
Tag.category_for(name)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -3,16 +3,13 @@
|
|||||||
<li><strong>Status</strong> <%= artist.status %></li>
|
<li><strong>Status</strong> <%= artist.status %></li>
|
||||||
|
|
||||||
<% if !artist.is_banned? || CurrentUser.is_member? %>
|
<% 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? %>
|
<% if artist.other_names.present? %>
|
||||||
<li><strong>Other Names</strong> <%= link_to_artists(artist.other_names) %></li>
|
<li><strong>Other Names</strong> <%= link_to_artists(artist.other_names) %></li>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if artist.group_name.present? %>
|
<% if artist.group_name.present? %>
|
||||||
<li><strong>Group</strong> <%= link_to_artist(artist.group_name) %></li>
|
<li><strong>Group</strong> <%= link_to_artist(artist.group_name) %></li>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if artist.members.any? %>
|
<% if artist.members.present? %>
|
||||||
<li><strong>Members</strong> <%= link_to_artists(artist.members.map(&:name)) %></li>
|
<li><strong>Members</strong> <%= link_to_artists(artist.members.map(&:name)) %></li>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if artist.domains.any? %>
|
<% if artist.domains.any? %>
|
||||||
@@ -23,7 +20,7 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
</ul>
|
</ul>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if artist.urls.any? %>
|
<% if artist.urls.present? %>
|
||||||
<li><strong>URLs</strong></li>
|
<li><strong>URLs</strong></li>
|
||||||
<ul>
|
<ul>
|
||||||
<% artist.urls.each do |url| %>
|
<% artist.urls.each do |url| %>
|
||||||
|
|||||||
@@ -64,21 +64,6 @@ class ArtistTest < ActiveSupport::TestCase
|
|||||||
should_not allow_value("").for(:name)
|
should_not allow_value("").for(:name)
|
||||||
end
|
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
|
context "that has been banned" do
|
||||||
setup do
|
setup do
|
||||||
@post = FactoryBot.create(:post, :tag_string => "aaa")
|
@post = FactoryBot.create(:post, :tag_string => "aaa")
|
||||||
|
|||||||
Reference in New Issue
Block a user