artists: move artist finding code from controller to model.
This commit is contained in:
@@ -101,14 +101,7 @@ class ArtistsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def finder
|
def finder
|
||||||
begin
|
@artists = Artist.find_artists(params[:url], params[:referer_url])
|
||||||
@artists = Artist.url_matches(params[:url]).order("id desc").limit(10)
|
|
||||||
if @artists.empty? && params[:referer_url].present? && params[:referer_url] != params[:url]
|
|
||||||
@artists = Artist.url_matches(params[:referer_url]).order("id desc").limit(20)
|
|
||||||
end
|
|
||||||
rescue PixivApiClient::Error => e
|
|
||||||
@artists = []
|
|
||||||
end
|
|
||||||
|
|
||||||
respond_with(@artists) do |format|
|
respond_with(@artists) do |format|
|
||||||
format.xml do
|
format.xml do
|
||||||
|
|||||||
@@ -357,6 +357,18 @@ class Artist < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
module SearchMethods
|
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)
|
def url_matches(string)
|
||||||
matches = find_all_by_url(string).map(&:id)
|
matches = find_all_by_url(string).map(&:id)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user