diff options
author | momo-i <momo-i@ampache> | 2008-09-03 22:44:01 +0000 |
---|---|---|
committer | momo-i <momo-i@ampache> | 2008-09-03 22:44:01 +0000 |
commit | 01670c6abda538b5b40893f5015bfc4913382841 (patch) | |
tree | d20886a34636087129877d3284dd1701d42daee1 /lib/class/song.class.php | |
parent | 64cbf29ff39637f91ab938e8370b67a604c74f9a (diff) | |
download | ampache-01670c6abda538b5b40893f5015bfc4913382841.tar.gz ampache-01670c6abda538b5b40893f5015bfc4913382841.tar.bz2 ampache-01670c6abda538b5b40893f5015bfc4913382841.zip |
simplify code, remove large if else statement
Diffstat (limited to 'lib/class/song.class.php')
-rw-r--r-- | lib/class/song.class.php | 72 |
1 files changed, 35 insertions, 37 deletions
diff --git a/lib/class/song.class.php b/lib/class/song.class.php index b524d126..6c97383f 100644 --- a/lib/class/song.class.php +++ b/lib/class/song.class.php @@ -78,46 +78,44 @@ class Song extends database_object { */ public static function build_cache($song_ids) { - if ($song_ids) { - $idlist = '(' . implode(',', $song_ids) . ')'; - - // Song data cache - $sql = "SELECT song.id,file,catalog,album,year,artist,". - "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::read($sql); + if (!is_array($song_ids) OR !count($song_ids)) { return false; } + + $idlist = '(' . implode(',', $song_ids) . ')'; - 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); - Tag::build_map_cache('song',$song_ids); - - // If we're rating this then cache them as well - if (Config::get('ratings')) { - Rating::build_cache('song',$song_ids); - } + // Song data cache + $sql = "SELECT song.id,file,catalog,album,year,artist,". + "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::read($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']; + } - // Build a cache for the song's extended table - $sql = "SELECT * FROM `song_data` WHERE `song_id` IN $idlist"; - $db_results = Dba::read($sql); + Artist::build_cache($artists); + Album::build_cache($albums); + Tag::build_cache($tags); + Tag::build_map_cache('song',$song_ids); - while ($row = Dba::fetch_assoc($db_results)) { - parent::add_to_cache('song_data',$row['song_id'],$row); - } - - return true; - } else { - return false; - } + // If we're rating this then cache them as well + if (Config::get('ratings')) { + Rating::build_cache('song',$song_ids); + } + + // Build a cache for the song's extended table + $sql = "SELECT * FROM `song_data` WHERE `song_id` IN $idlist"; + $db_results = Dba::read($sql); + + while ($row = Dba::fetch_assoc($db_results)) { + parent::add_to_cache('song_data',$row['song_id'],$row); + } + + return true; } // build_cache |