artists: move artist finding code from controller to model.
This commit is contained in:
@@ -101,14 +101,7 @@ class ArtistsController < ApplicationController
|
||||
end
|
||||
|
||||
def finder
|
||||
begin
|
||||
@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
|
||||
@artists = Artist.find_artists(params[:url], params[:referer_url])
|
||||
|
||||
respond_with(@artists) do |format|
|
||||
format.xml do
|
||||
|
||||
@@ -357,6 +357,18 @@ 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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user