mongodb select tracks optimized
This commit is contained in:
parent
fbf7a8480a
commit
91a664016e
|
@ -11,13 +11,22 @@ class ArtistController < ApplicationController
|
||||||
name = params[:name].gsub('+', ' ')
|
name = params[:name].gsub('+', ' ')
|
||||||
end
|
end
|
||||||
@artist = Artist.getByName(name)
|
@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
|
end
|
||||||
|
|
||||||
def autocomplete
|
def autocomplete
|
||||||
autocomplete = Artist.getLastFmAutocomplete(params[:query])
|
autocomplete = Artist.getLastFmAutocomplete(params[:query])
|
||||||
return render :nothing => true if autocomplete.nil?
|
return render :nothing => true if autocomplete.nil?
|
||||||
suggestions = []
|
suggestions = []
|
||||||
pp autocomplete["response"]
|
|
||||||
autocomplete["response"]["docs"].each do |doc|
|
autocomplete["response"]["docs"].each do |doc|
|
||||||
suggestions << doc["artist"] unless suggestions.include?(doc["artist"])
|
suggestions << doc["artist"] unless suggestions.include?(doc["artist"])
|
||||||
end
|
end
|
||||||
|
|
|
@ -32,5 +32,30 @@ class Album < ActiveRecord::Base
|
||||||
m[3][1]
|
m[3][1]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def tracksInDb
|
||||||
|
tracks = []
|
||||||
|
result = []
|
||||||
|
tracks_in_db = []
|
||||||
|
track_ids = []
|
||||||
|
|
||||||
|
self.releases.first.tracks.each do |track|
|
||||||
|
tracks << track
|
||||||
|
track_ids << track.id.to_s
|
||||||
|
end
|
||||||
|
in_db = TrackData.any_in(id: track_ids).only("id")
|
||||||
|
unless in_db.nil?
|
||||||
|
in_db.each do |track|
|
||||||
|
tracks_in_db << track["id"].to_i;
|
||||||
|
end
|
||||||
|
end
|
||||||
|
tracks.each do |track|
|
||||||
|
result << {
|
||||||
|
:object => track,
|
||||||
|
:in_db => tracks_in_db.include?(track.id) ? nil : true
|
||||||
|
}
|
||||||
|
end
|
||||||
|
result
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
class Track < ActiveRecord::Base
|
class Track < ActiveRecord::Base
|
||||||
set_table_name 'musicbrainz.bh_track'
|
set_table_name 'musicbrainz.bh_track'
|
||||||
belongs_to :release
|
belongs_to :release
|
||||||
|
end
|
||||||
|
|
||||||
def inDb
|
|
||||||
! TrackData.where(id: id.to_s).empty?
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
|
@ -5,22 +5,19 @@
|
||||||
</div>
|
</div>
|
||||||
<% else %>
|
<% else %>
|
||||||
<h1 class="artist"><%= @artist.name %></h1>
|
<h1 class="artist"><%= @artist.name %></h1>
|
||||||
<% @artist.albums.each do |album| %>
|
<% @albums.each do |album| %>
|
||||||
<% unless album.releases.empty? %>
|
|
||||||
<div class="album">
|
<div class="album">
|
||||||
<div class="pic"><img src="<%= album.cover(@artist.name) %>" width="250" height="250" alt=""/></div>
|
<div class="pic"><img src="<%= album[:object].cover(@artist.name) %>" width="250" height="250" alt=""/></div>
|
||||||
<h3 class="name"><%= album.name %> <%= (album.year ? album.year : '') %></h3>
|
<h3 class="name"><%= album[:object].name %> <%= (album[:object].year ? album[:object].year : '') %></h3>
|
||||||
<%
|
|
||||||
releases = album.releases
|
|
||||||
first_release = releases.first
|
|
||||||
%>
|
|
||||||
<ul class="tracks">
|
<ul class="tracks">
|
||||||
<% first_release.tracks.each do |track| %>
|
<% album[:tracks].each do |track| %>
|
||||||
<li id="<%= track.id %>">
|
<li id="<%= track[:object].id %>">
|
||||||
<span class="play<%= (track.inDb ? '' : ' disabled') %>"><img src="/images/player/play.svg" alt="play" /></span>
|
<span class="play<%= (track[:in_db].nil? ? '' : ' disabled') %>">
|
||||||
<span class="track-name"><%= track.name %></span>
|
<img src="/images/player/play.svg" alt="play" />
|
||||||
<% unless track.length.nil? %>
|
</span>
|
||||||
<span class="duration" data-length="<%= track.length %>"><%= track.length.toTime %></span>
|
<span class="track-name"><%= track[:object].name %></span>
|
||||||
|
<% unless track[:object].length.nil? %>
|
||||||
|
<span class="duration" data-length="<%= track[:object].length %>"><%= track[:object].length.toTime %></span>
|
||||||
<% end %>
|
<% end %>
|
||||||
</li>
|
</li>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
@ -28,5 +25,4 @@
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue