1
0
Fork 0

Cache clear hooks, track length update fix

This commit is contained in:
magnolia-fan 2011-11-29 03:22:29 +04:00
parent 549e27e0df
commit 94ae2ff3b0
7 changed files with 26 additions and 13 deletions

View File

@ -91,9 +91,9 @@ class window.Player
_vk_music.search track.artist, track.name, track.length, (audio) ->
if audio is null
_session.query '/track/report', { id: track.id }, (r) ->
if r.status is 'success'
$('.playlist li[data-id="'+track.id+'"]').addClass("unavailable")
$($('.album div[data-id="'+track.id+'"]').siblings()[0]).addClass("unavailable")
if r.result is 'success'
$(".playlist li[data-id='#{track.id}']").addClass("unavailable")
$($(".album div[data-id='#{track.id}']").siblings()[0]).addClass("unavailable")
_player.setTrack _player.nextTrack()
else
_player.playSource audio.url
@ -103,18 +103,15 @@ class window.Player
s = len - Math.floor(len / 60) * 60
duration = m + ':' + (if s < 10 then '0' else '') + s
_session.query '/track/update_length', { track_id: track.id, length: len }, (r) ->
if r.status is 'success'
$('.playlist li[data-id="'+track.id+'"] .song-duration').text(duration)
$($('.album div[data-id="'+track.id+'"]').siblings()[0]).text(duration)
if r.result is 'success'
$(".playlist li[data-id='#{track.id}'] .song-duration").text(duration)
$($(".album div[data-id='#{track.id}']").siblings()[0]).text(duration)
_player.updateNowListening track
false
false
getTrackInfo: (id) ->
for track in _player.playlist
if parseInt(track.id, 10) == parseInt(id, 10)
return track
false
@library[id]
getAlbumInfo: (id) ->
for album in _player.albums

View File

@ -59,7 +59,7 @@ class window.VkontakteMusic
data
prepareQuery: (artist, track) ->
artist+" "+this.trim(/[\w\d\s]+/.exec(track)[0]).replace(/\(.*\)/i, '').split('/')[0]
artist+" "+this.trim(/[a-zA-Zа-яА-Я0-9\s-]+/.exec(track)[0]).replace(/\(.*\)/i, '').split('/')[0]
trim: (str) ->
while str.indexOf(' ') isnt -1

View File

@ -32,7 +32,7 @@ class ArtistController < ApplicationController
title: @artist.name,
status: @artist.status_str,
callback: {object: :player, action: :updateLibrary},
cache_for: 1.day
cache_for: (1.day if @artist.status_str == "ok")
)
end

View File

@ -5,6 +5,7 @@ class Album < ActiveRecord::Base
has_many :release_formats, :through => :album_formats
default_scope where(:master => true)
after_save :clear_artist_cache
def self.with_format f
joins(:release_formats).where(:release_formats => { :hash => f.to_s })
@ -18,4 +19,10 @@ class Album < ActiveRecord::Base
tracks: tracks.map(&:serialize)
}
end
private
def clear_artist_cache
artist.clear_cache
end
end

View File

@ -6,6 +6,7 @@ class Artist < ActiveRecord::Base
has_many :playlists
after_initialize :prepare_description
after_save :clear_cache
def status_str
%w(loading ok fail)[self.status]

View File

@ -4,6 +4,8 @@ class Track < ActiveRecord::Base
has_many :artists, :through => :track_artists
has_many :playlist_items
after_save :clear_artist_cache
def duration
if self.length
time = self.length
@ -28,4 +30,10 @@ class Track < ActiveRecord::Base
album_pic: album.pic_url
}
end
private
def clear_artist_cache
artists.each(&:clear_cache)
end
end

View File

@ -155,7 +155,7 @@ class Discogs
}
end
end
ap albums
albums
end
def self.search_for_artist name