mongodb select tracks optimized

This commit is contained in:
Hipster Hitman
2011-04-12 06:46:07 +04:00
parent fbf7a8480a
commit 91a664016e
4 changed files with 48 additions and 21 deletions
+11 -2
View File
@@ -5,19 +5,28 @@ class ArtistController < ApplicationController
if params[:name].nil?
name = ''
else
if request.request_method == 'POST'
if request.request_method == 'POST'
redirect_to :action => 'view', :name => params[:name].gsub(' ', '+')
end
name = params[:name].gsub('+', ' ')
end
@artist = Artist.getByName(name)
@albums = []
@artist.albums.each do |album|
unless album.releases.empty?
tracks = album.tracksInDb()
@albums << {
:object => album,
:tracks => tracks
}
end
end
end
def autocomplete
autocomplete = Artist.getLastFmAutocomplete(params[:query])
return render :nothing => true if autocomplete.nil?
suggestions = []
pp autocomplete["response"]
autocomplete["response"]["docs"].each do |doc|
suggestions << doc["artist"] unless suggestions.include?(doc["artist"])
end