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
+7
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
+1
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]
+8
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