diff options
author | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2008-05-26 04:08:45 +0000 |
---|---|---|
committer | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2008-05-26 04:08:45 +0000 |
commit | 13ae6a0371ae26023880a0ad69b3b1587db8dd76 (patch) | |
tree | ec0f94a7ee29fb4d34056f3e5a79bd620ad93161 /lib/class/song.class.php | |
parent | 9803be045ba3895cc981d5e7e22fd80f80d6544d (diff) | |
download | ampache-13ae6a0371ae26023880a0ad69b3b1587db8dd76.tar.gz ampache-13ae6a0371ae26023880a0ad69b3b1587db8dd76.tar.bz2 ampache-13ae6a0371ae26023880a0ad69b3b1587db8dd76.zip |
show the top 2 tags on songs, sync fixes from /branches/3.4 improved caching on song object
Diffstat (limited to 'lib/class/song.class.php')
-rw-r--r-- | lib/class/song.class.php | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/lib/class/song.class.php b/lib/class/song.class.php index 0a20e4b7..f38c7985 100644 --- a/lib/class/song.class.php +++ b/lib/class/song.class.php @@ -82,19 +82,30 @@ class Song extends database_object { // Song data cache $sql = "SELECT song.id,file,catalog,album,year,artist,". - "title,bitrate,rate,mode,size,time,track,played,song.enabled,update_time,". - "addition_time FROM `song` WHERE `song`.`id` IN - $idlist"; + "title,bitrate,rate,mode,size,time,track,played,song.enabled,update_time,tag_map.tag_id,". + "addition_time FROM `song` " . + "LEFT JOIN `tag_map` ON `tag_map`.`object_id`=`song`.`id` AND `tag_map`.`object_type`='song' " . + "WHERE `song`.`id` IN $idlist"; $db_results = Dba::query($sql); while ($row = Dba::fetch_assoc($db_results)) { parent::add_to_cache('song',$row['id'],$row); $artists[$row['artist']] = $row['artist']; $albums[$row['album']] = $row['album']; + $tags[$row['tag_id']] = $row['tag_id']; } Artist::build_cache($artists); Album::build_cache($albums); + Tag::build_cache($tags); + + // Build a cache for the song's extended table + $sql = "SELECT * FROM `song_data` WHERE `song_id` IN $idlist"; + $db_results = Dba::query($sql); + + while ($row = Dba::fetch_assoc($db_results)) { + parent::add_to_cache('song_data',$row['song_id'],$row); + } return true; @@ -133,14 +144,20 @@ class Song extends database_object { * current object */ public function _get_ext_info() { - global $song_data_cache; - if (isset($song_data_cache[intval($this->id)])) - return $song_data_cache[intval($this->id)]; - $sql = "SELECT * FROM song_data WHERE `song_id`='" . Dba::escape($this->id) . "'"; + + $id = intval($this->id); + + if (parent::is_cached('song_data',$id)) { + return parent::get_from_cache('song_data',$id); + } + + $sql = "SELECT * FROM song_data WHERE `song_id`='$id'"; $db_results = Dba::query($sql); $results = Dba::fetch_assoc($db_results); + parent::add_to_cache('song_data',$id,$results); + return $results; } // _get_ext_info @@ -652,7 +669,12 @@ class Song extends database_object { // Get the top tags $tags = Tag::get_top_tags('song',$this->id); - $this->f_tags = implode(', ',$tags); + foreach ($tags as $tag_id) { + $tag = new Tag($tag_id); + $this->f_tags .= $tag->name . ', '; + } + + $this->f_tags = rtrim($this->f_tags,', '); // Format the size $this->f_size = sprintf("%.2f",($this->size/1048576)); |