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/artist.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/artist.class.php')
-rw-r--r-- | lib/class/artist.class.php | 38 |
1 files changed, 18 insertions, 20 deletions
diff --git a/lib/class/artist.class.php b/lib/class/artist.class.php index ae742ded..837c2154 100644 --- a/lib/class/artist.class.php +++ b/lib/class/artist.class.php @@ -78,32 +78,30 @@ class Artist extends database_object { * this attempts to build a cache of the data from the passed albums all in one query */ public static function build_cache($ids,$extra=false) { - if($ids) { - $idlist = '(' . implode(',', $ids) . ')'; + if(!is_array($ids) OR !count($ids)) { return false; } - $sql = "SELECT * FROM `artist` WHERE `id` IN $idlist"; - $db_results = Dba::query($sql); + $idlist = '(' . implode(',', $ids) . ')'; + + $sql = "SELECT * FROM `artist` WHERE `id` IN $idlist"; + $db_results = Dba::query($sql); - while ($row = Dba::fetch_assoc($db_results)) { - parent::add_to_cache('artist',$row['id'],$row); - } + while ($row = Dba::fetch_assoc($db_results)) { + parent::add_to_cache('artist',$row['id'],$row); + } - // If we need to also pull the extra information, this is normally only used when we are doing the human display - if ($extra) { - $sql = "SELECT `song`.`artist`, COUNT(`song`.`id`) AS `song_count`, COUNT(DISTINCT `song`.`album`) AS `album_count`, SUM(`song`.`time`) AS `time` FROM `song` " . - "WHERE `song`.`artist` IN $idlist GROUP BY `song`.`artist`"; - $db_results = Dba::query($sql); + // If we need to also pull the extra information, this is normally only used when we are doing the human display + if ($extra) { + $sql = "SELECT `song`.`artist`, COUNT(`song`.`id`) AS `song_count`, COUNT(DISTINCT `song`.`album`) AS `album_count`, SUM(`song`.`time`) AS `time` FROM `song` " . + "WHERE `song`.`artist` IN $idlist GROUP BY `song`.`artist`"; + $db_results = Dba::query($sql); - while ($row = Dba::fetch_assoc($db_results)) { - parent::add_to_cache('artist_extra',$row['artist'],$row); - } + while ($row = Dba::fetch_assoc($db_results)) { + parent::add_to_cache('artist_extra',$row['artist'],$row); + } - } // end if extra + } // end if extra - return true; - } else { - return false; - } + return true; } // build_cache |