Optimized code
This commit is contained in:
parent
ba65a8370c
commit
7ec4071652
|
@ -1,4 +1,3 @@
|
||||||
require 'open-uri'
|
|
||||||
require 'musicbrainz'
|
require 'musicbrainz'
|
||||||
|
|
||||||
class ArtistController < ApplicationController
|
class ArtistController < ApplicationController
|
||||||
|
@ -19,7 +18,7 @@ class ArtistController < ApplicationController
|
||||||
return render json: { status: 'not_found' }
|
return render json: { status: 'not_found' }
|
||||||
end
|
end
|
||||||
best_match = results[0][:name]
|
best_match = results[0][:name]
|
||||||
if best_match != artist_name and (best_match.downcase == artist_name.downcase or best_match.downcase == 'the '+ artist_name.downcase)
|
if best_match != artist_name and similar_names(artist_name, best_match)
|
||||||
return render json: { status: 'corrected', correct_name: best_match }
|
return render json: { status: 'corrected', correct_name: best_match }
|
||||||
elsif results[0][:name] == artist_name
|
elsif results[0][:name] == artist_name
|
||||||
queue_loading(artist_name, results[0][:mbid])
|
queue_loading(artist_name, results[0][:mbid])
|
||||||
|
@ -37,7 +36,11 @@ class ArtistController < ApplicationController
|
||||||
return render json: { status: 'fail', html: render_compact_partial(:fail) }
|
return render json: { status: 'fail', html: render_compact_partial(:fail) }
|
||||||
end
|
end
|
||||||
|
|
||||||
render json: { status: @artist.status_str, artist: @artist, html: render_compact_partial(:page) }, include: {albums: {include: {tracks: {}}}}
|
render json: {
|
||||||
|
status: @artist.status_str,
|
||||||
|
artist: @artist,
|
||||||
|
html: render_compact_partial(:page) }, include: {albums: {include: {tracks: {}}}
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -50,4 +53,8 @@ private
|
||||||
@artist = Artist.create( name: artist_name, mbid: mbid, status: 0 )
|
@artist = Artist.create( name: artist_name, mbid: mbid, status: 0 )
|
||||||
Delayed::Job.enqueue(LoadArtistJob.new(artist_name))
|
Delayed::Job.enqueue(LoadArtistJob.new(artist_name))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def similar_names name1, name2
|
||||||
|
(name2.downcase == name1.downcase or name2.downcase == 'the '+ name1.downcase)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue