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

View File

@ -59,7 +59,7 @@ class window.VkontakteMusic
data data
prepareQuery: (artist, track) -> 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) -> trim: (str) ->
while str.indexOf(' ') isnt -1 while str.indexOf(' ') isnt -1

View File

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

View File

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

View File

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

View File

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

View File

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