Merge pull request #3889 from evazion/fix-replace-artist-finder

Cleanup artist finder
This commit is contained in:
Albert Yi
2018-09-12 11:44:42 -07:00
committed by GitHub
11 changed files with 19 additions and 96 deletions

View File

@@ -92,20 +92,6 @@ class ArtistsController < ApplicationController
end
end
def finder
@artists = Artist.find_artists(params[:url], params[:referer_url])
respond_with(@artists) do |format|
format.xml do
render :xml => @artists.to_xml(:include => [:sorted_urls], :root => "artists")
end
format.json do
render :json => @artists.to_json(:include => [:sorted_urls])
expires_in params[:expiry].to_i.days if params[:expiry]
end
end
end
private
def load_artist

View File

@@ -441,7 +441,7 @@ Post.initialize_post_sections = function() {
$("#share").hide();
$("#post_tag_string").focus().selectEnd().height($("#post_tag_string")[0].scrollHeight);
$("#related-tags-button").trigger("click");
$("#find-artist-button").trigger("click");
$("#fetch-data-manual").trigger("click");
$("#recommended").hide();
} else if (e.target.hash === "#recommended") {
$("#comments").hide();

View File

@@ -1,3 +1,4 @@
import Upload from './uploads';
import Utility from './utility';
import Cookie from './cookie';
@@ -16,7 +17,6 @@ RelatedTag.initialize_buttons = function() {
<% TagCategory.related_button_list.each do |category| %>
RelatedTag.common_bind("#related-<%= category %>-button", "<%= category %>"); // eslint-disable-line indent
<% end %>
$("#find-artist-button").on("click.danbooru", RelatedTag.find_artist);
}
RelatedTag.tags_include = function(name) {
@@ -281,21 +281,6 @@ RelatedTag.toggle_tag = function(e) {
e.preventDefault();
}
RelatedTag.find_artist = function(e) {
$("#artist-tags").html("<em>Loading...</em>");
var url = $("#upload_source,#post_source");
var referer_url = $("#upload_referer_url");
$.get("/artists/finder.json", {"url": url.val(), "referer_url": referer_url.val()}, RelatedTag.process_artist);
if (e) {
e.preventDefault();
}
}
RelatedTag.process_artist = function(data) {
RelatedTag.recent_artists = data;
RelatedTag.build_all();
}
RelatedTag.toggle = function() {
if ($("#related-tags").is(":visible")) {
RelatedTag.hide();
@@ -332,7 +317,7 @@ RelatedTag.disable_artist_url = function(e) {
is_active: false
}
}
}).done(RelatedTag.find_artist);
}).done(Upload.fetch_data_manual);
}
});
return false;

View File

@@ -129,6 +129,8 @@ module Sources
normalize_for_artist_finder.present?
end
# The url to use for artist finding purposes. This will be stored in the
# artist entry. Normally this will be the profile url.
def normalize_for_artist_finder
profile_url || url
end
@@ -139,8 +141,7 @@ module Sources
end
def artists
url = profile_url.presence || image_url.presence
Artist.find_artists(url)
Artist.url_matches(normalize_for_artist_finder)
end
def file_url

View File

@@ -66,14 +66,6 @@ module Sources::Strategies
""
end
def artists
if profile_url.present?
Artist.find_artists(profile_url)
else
[]
end
end
def artist_name
return "" if api_response.blank?
api_response.attrs[:user][:screen_name]

View File

@@ -148,7 +148,7 @@ class Artist < ApplicationRecord
%r!\Ahttps?://(?:[a-zA-Z0-9_-]+\.)*#{domain}/\z!i
end)
def find_all_by_url(url)
def url_matches(url)
url = ArtistUrl.normalize(url)
artists = []
@@ -163,7 +163,7 @@ class Artist < ApplicationRecord
break if url =~ SITE_BLACKLIST_REGEXP
end
artists.inject({}) {|h, x| h[x.name] = x; h}.values.slice(0, 20)
where(id: artists.uniq(&:name).take(20))
end
end
@@ -456,40 +456,6 @@ class Artist < ApplicationRecord
end
module SearchMethods
def find_artists(url, referer_url = nil)
artists = url_matches(url).order("id desc").limit(10)
if artists.empty? && referer_url.present? && referer_url != url
artists = url_matches(referer_url).order("id desc").limit(20)
end
artists
rescue PixivApiClient::Error => e
[]
end
def url_matches(string)
matches = find_all_by_url(string).map(&:id)
if matches.any?
where("id in (?)", matches)
elsif matches = search_for_profile(string)
where("id in (?)", matches)
else
where("false")
end
end
def search_for_profile(url)
source = Sources::Strategies.find(url)
find_all_by_url(source.profile_url)
rescue Net::OpenTimeout, PixivApiClient::Error
raise if Rails.env.test?
nil
rescue Exception
nil
end
def other_names_match(string)
if string =~ /\*/ && CurrentUser.is_builder?
where("artists.other_names ILIKE ? ESCAPE E'\\\\'", string.to_escaped_for_sql_like)

View File

@@ -69,7 +69,6 @@
<%= f.label :source %>
<%= f.text_field :source %>
<%= button_tag "Similar", :id => "similar-button", :type => "button", :class => "ui-button ui-widget ui-corner-all sub gradient" %>
<%= button_tag "Artist", :id => "find-artist-button", :type => "button", :class => "ui-button ui-widget ui-corner-all sub gradient" %>
</div>
<% if Danbooru.config.iqdbs_server %>

View File

@@ -43,7 +43,6 @@
<%= f.label :source %>
<%= f.text_field :source, :size => 50, :value => params[:url] %>
<%= button_tag "Similar", :id => "similar-button", :type => "button", :class => "ui-button ui-widget ui-corner-all sub gradient" %>
<%= button_tag "Artist", :id => "find-artist-button", :type => "button", :class => "ui-button ui-widget ui-corner-all sub gradient" %>
<span class="hint">You can enter a URL to have <%= Danbooru.config.app_name %> automatically download and process it</span>
</div>