Changeset 1736
- Timestamp:
- 09/02/08 17:06:29 (3 months ago)
- Location:
- trunk
- Files:
-
- 8 modified
-
lib/class/album.class.php (modified) (1 diff)
-
lib/class/artist.class.php (modified) (1 diff)
-
lib/class/rating.class.php (modified) (1 diff)
-
lib/class/song.class.php (modified) (1 diff)
-
lib/class/tag.class.php (modified) (2 diffs)
-
lib/debug.lib.php (modified) (1 diff)
-
lib/init.php (modified) (1 diff)
-
templates/show_random_albums.inc.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/class/album.class.php
r1730 r1736 96 96 public static function build_cache($ids,$extra=false) { 97 97 98 $idlist = '(' . implode(',', $ids) . ')'; 99 100 $sql = "SELECT * FROM `album` WHERE `id` IN $idlist"; 101 $db_results = Dba::query($sql); 98 if ($ids) { 99 $idlist = '(' . implode(',', $ids) . ')'; 100 101 $sql = "SELECT * FROM `album` WHERE `id` IN $idlist"; 102 $db_results = Dba::query($sql); 102 103 103 while ($row = Dba::fetch_assoc($db_results)) { 104 parent::add_to_cache('album',$row['id'],$row); 105 } 106 107 // If we're extra'ing cache the extra info as well 108 if ($extra) { 109 $sql = "SELECT COUNT(DISTINCT(song.artist)) as artist_count,COUNT(song.id) AS song_count,artist.name AS artist_name" . 110 ",artist.prefix AS artist_prefix,album_data.art AS has_art,album_data.thumb AS has_thumb, artist.id AS artist_id,`song`.`album`". 111 "FROM `song` " . 112 "INNER JOIN `artist` ON `artist`.`id`=`song`.`artist` " . 113 "LEFT JOIN `album_data` ON `album_data`.`album_id` = `song`.`album` " . 114 "WHERE `song`.`album` IN $idlist GROUP BY `song`.`album`"; 115 $db_results = Dba::read($sql); 116 117 while ($row = Dba::fetch_assoc($db_results)) { 118 $row['has_art'] = make_bool($row['has_art']); 119 $row['has_thumb'] = make_bool($row['has_thumb']); 120 parent::add_to_cache('album_extra',$row['album'],$row); 121 } // while rows 122 } // if extra 104 while ($row = Dba::fetch_assoc($db_results)) { 105 parent::add_to_cache('album',$row['id'],$row); 106 } 107 108 // If we're extra'ing cache the extra info as well 109 if ($extra) { 110 $sql = "SELECT COUNT(DISTINCT(song.artist)) as artist_count,COUNT(song.id) AS song_count,artist.name AS artist_name" . 111 ",artist.prefix AS artist_prefix,album_data.art AS has_art,album_data.thumb AS has_thumb, artist.id AS artist_id,`song`.`album`". 112 "FROM `song` " . 113 "INNER JOIN `artist` ON `artist`.`id`=`song`.`artist` " . 114 "LEFT JOIN `album_data` ON `album_data`.`album_id` = `song`.`album` " . 115 "WHERE `song`.`album` IN $idlist GROUP BY `song`.`album`"; 116 $db_results = Dba::read($sql); 117 118 while ($row = Dba::fetch_assoc($db_results)) { 119 $row['has_art'] = make_bool($row['has_art']); 120 $row['has_thumb'] = make_bool($row['has_thumb']); 121 parent::add_to_cache('album_extra',$row['album'],$row); 122 } // while rows 123 } // if extra 124 125 return true; 126 } else { 127 return false; 128 } 123 129 124 130 } // build_cache -
trunk/lib/class/artist.class.php
r1698 r1736 79 79 */ 80 80 public static function build_cache($ids,$extra=false) { 81 $idlist = '(' . implode(',', $ids) . ')'; 82 83 $sql = "SELECT * FROM `artist` WHERE `id` IN $idlist"; 84 $db_results = Dba::query($sql); 85 86 while ($row = Dba::fetch_assoc($db_results)) { 87 parent::add_to_cache('artist',$row['id'],$row); 81 if($ids) { 82 $idlist = '(' . implode(',', $ids) . ')'; 83 84 $sql = "SELECT * FROM `artist` WHERE `id` IN $idlist"; 85 $db_results = Dba::query($sql); 86 87 while ($row = Dba::fetch_assoc($db_results)) { 88 parent::add_to_cache('artist',$row['id'],$row); 89 } 90 91 // If we need to also pull the extra information, this is normally only used when we are doing the human display 92 if ($extra) { 93 $sql = "SELECT `song`.`artist`, COUNT(`song`.`id`) AS `song_count`, COUNT(DISTINCT `song`.`album`) AS `album_count`, SUM(`song`.`time`) AS `time` FROM `song` " . 94 "WHERE `song`.`artist` IN $idlist GROUP BY `song`.`artist`"; 95 $db_results = Dba::query($sql); 96 97 while ($row = Dba::fetch_assoc($db_results)) { 98 parent::add_to_cache('artist_extra',$row['artist'],$row); 99 } 100 101 } // end if extra 102 103 return true; 104 } else { 105 return false; 88 106 } 89 90 // If we need to also pull the extra information, this is normally only used when we are doing the human display91 if ($extra) {92 $sql = "SELECT `song`.`artist`, COUNT(`song`.`id`) AS `song_count`, COUNT(DISTINCT `song`.`album`) AS `album_count`, SUM(`song`.`time`) AS `time` FROM `song` " .93 "WHERE `song`.`artist` IN $idlist GROUP BY `song`.`artist`";94 $db_results = Dba::query($sql);95 96 while ($row = Dba::fetch_assoc($db_results)) {97 parent::add_to_cache('artist_extra',$row['artist'],$row);98 }99 100 } // end if extra101 107 102 108 } // build_cache -
trunk/lib/class/rating.class.php
r1640 r1736 66 66 public static function build_cache($type, $ids) { 67 67 68 $user_id = Dba::escape($GLOBALS['user']->id); 69 70 $idlist = '(' . implode(',', $ids) . ')'; 71 $sql = "SELECT `rating`, `object_id`,`rating`.`rating` FROM `rating` WHERE `user`='$user_id' AND `object_id` IN $idlist " . 72 "AND `object_type`='$type'"; 73 $db_results = Dba::read($sql); 74 75 while ($row = Dba::fetch_assoc($db_results)) { 76 $user[$row['object_id']] = $row['rating']; 77 } 78 79 $sql = "SELECT `rating`,`object_id` FROM `rating` WHERE `object_id` IN $idlist AND `object_type`='$type'"; 80 $db_results = Dba::read($sql); 81 82 while ($row = Dba::fetch_assoc($db_results)) { 83 $rating[$row['object_id']]['rating'] += $row['rating']; 84 $rating[$row['object_id']]['total']++; 85 } 86 87 foreach ($ids as $id) { 88 parent::add_to_cache('rating_' . $type . '_user',$id,intval($user[$id])); 89 90 // Do the bit of math required to store this 91 if (!isset($rating[$id])) { 92 $entry = array('average'=>'0','percise'=>'0'); 68 if ($ids) { 69 $user_id = Dba::escape($GLOBALS['user']->id); 70 71 $idlist = '(' . implode(',', $ids) . ')'; 72 $sql = "SELECT `rating`, `object_id`,`rating`.`rating` FROM `rating` WHERE `user`='$user_id' AND `object_id` IN $idlist " . 73 "AND `object_type`='$type'"; 74 $db_results = Dba::read($sql); 75 76 while ($row = Dba::fetch_assoc($db_results)) { 77 $user[$row['object_id']] = $row['rating']; 78 } 79 80 $sql = "SELECT `rating`,`object_id` FROM `rating` WHERE `object_id` IN $idlist AND `object_type`='$type'"; 81 $db_results = Dba::read($sql); 82 83 while ($row = Dba::fetch_assoc($db_results)) { 84 $rating[$row['object_id']]['rating'] += $row['rating']; 85 $rating[$row['object_id']]['total']++; 86 } 87 88 foreach ($ids as $id) { 89 parent::add_to_cache('rating_' . $type . '_user',$id,intval($user[$id])); 90 91 // Do the bit of math required to store this 92 if (!isset($rating[$id])) { 93 $entry = array('average'=>'0','percise'=>'0'); 94 } 95 else { 96 $average = round($rating[$id]['rating']/$rating[$id]['total'],1); 97 $entry = array('average'=>floor($average),'percise'=>$average); 98 } 99 100 parent::add_to_cache('rating_' . $type . '_all',$id,$entry); 93 101 } 94 else { 95 $average = round($rating[$id]['rating']/$rating[$id]['total'],1); 96 $entry = array('average'=>floor($average),'percise'=>$average); 97 } 98 99 parent::add_to_cache('rating_' . $type . '_all',$id,$entry); 100 } 101 102 return true; 102 103 return true; 104 } else { 105 return false; 106 } 103 107 104 108 } // build_cache -
trunk/lib/class/song.class.php
r1640 r1736 79 79 public static function build_cache($song_ids) { 80 80 81 $idlist = '(' . implode(',', $song_ids) . ')'; 81 if ($ids) { 82 $idlist = '(' . implode(',', $song_ids) . ')'; 82 83 83 // Song data cache84 $sql = "SELECT song.id,file,catalog,album,year,artist,".85 "title,bitrate,rate,mode,size,time,track,played,song.enabled,update_time,tag_map.tag_id,".86 "addition_time FROM `song` " .87 "LEFT JOIN `tag_map` ON `tag_map`.`object_id`=`song`.`id` AND `tag_map`.`object_type`='song' " .88 "WHERE `song`.`id` IN $idlist";89 $db_results = Dba::read($sql);84 // Song data cache 85 $sql = "SELECT song.id,file,catalog,album,year,artist,". 86 "title,bitrate,rate,mode,size,time,track,played,song.enabled,update_time,tag_map.tag_id,". 87 "addition_time FROM `song` " . 88 "LEFT JOIN `tag_map` ON `tag_map`.`object_id`=`song`.`id` AND `tag_map`.`object_type`='song' " . 89 "WHERE `song`.`id` IN $idlist"; 90 $db_results = Dba::read($sql); 90 91 91 while ($row = Dba::fetch_assoc($db_results)) {92 parent::add_to_cache('song',$row['id'],$row);93 $artists[$row['artist']] = $row['artist'];94 $albums[$row['album']] = $row['album'];95 $tags[$row['tag_id']] = $row['tag_id'];96 }97 98 Artist::build_cache($artists);99 Album::build_cache($albums);100 Tag::build_cache($tags);101 Tag::build_map_cache('song',$song_ids);102 103 // If we're rating this then cache them as well104 if (Config::get('ratings')) {105 Rating::build_cache('song',$song_ids);106 }107 108 // Build a cache for the song's extended table109 $sql = "SELECT * FROM `song_data` WHERE `song_id` IN $idlist";110 $db_results = Dba::read($sql);111 112 while ($row = Dba::fetch_assoc($db_results)) {113 parent::add_to_cache('song_data',$row['song_id'],$row);114 }92 while ($row = Dba::fetch_assoc($db_results)) { 93 parent::add_to_cache('song',$row['id'],$row); 94 $artists[$row['artist']] = $row['artist']; 95 $albums[$row['album']] = $row['album']; 96 $tags[$row['tag_id']] = $row['tag_id']; 97 } 98 99 Artist::build_cache($artists); 100 Album::build_cache($albums); 101 Tag::build_cache($tags); 102 Tag::build_map_cache('song',$song_ids); 103 104 // If we're rating this then cache them as well 105 if (Config::get('ratings')) { 106 Rating::build_cache('song',$song_ids); 107 } 108 109 // Build a cache for the song's extended table 110 $sql = "SELECT * FROM `song_data` WHERE `song_id` IN $idlist"; 111 $db_results = Dba::read($sql); 112 113 while ($row = Dba::fetch_assoc($db_results)) { 114 parent::add_to_cache('song_data',$row['song_id'],$row); 115 } 115 116 116 return true; 117 return true; 118 } else { 119 return false; 120 } 117 121 118 122 } // build_cache -
trunk/lib/class/tag.class.php
r1626 r1736 78 78 public static function build_cache($ids) { 79 79 80 $idlist = '(' . implode(',',$ids) . ')'; 81 82 $sql = "SELECT * FROM `tag` WHERE `id` IN $idlist"; 83 $db_results = Dba::query($sql); 84 85 while ($row = Dba::fetch_assoc($db_results)) { 86 parent::add_to_cache('tag',$row['id'],$row); 87 } 88 89 return true; 80 if ($ids) { 81 $idlist = '(' . implode(',',$ids) . ')'; 82 83 $sql = "SELECT * FROM `tag` WHERE `id` IN $idlist"; 84 $db_results = Dba::query($sql); 85 86 while ($row = Dba::fetch_assoc($db_results)) { 87 parent::add_to_cache('tag',$row['id'],$row); 88 } 89 90 return true; 91 } else { 92 return false; 93 } 90 94 91 95 } // build_cache … … 97 101 public static function build_map_cache($type,$ids) { 98 102 99 $type = self::validate_type($type); 100 $idlist = '(' . implode(',',$ids) . ')'; 101 102 $sql = "SELECT COUNT(`tag_map`.`id`) AS `count`,`tag`.`id`,`tag_map`.`object_id` FROM `tag_map` " . 103 "INNER JOIN `tag` ON `tag`.`id`=`tag_map`.`tag_id` " . 104 "WHERE `tag_map`.`object_type`='$type' AND `tag_map`.`object_id` IN $idlist " . 105 "GROUP BY `tag_map`.`object_id` ORDER BY `count` DESC"; 106 $db_results = Dba::query($sql); 107 108 while ($row = Dba::fetch_assoc($db_results)) { 109 $tags[$row['object_id']][] = $row; 110 } 111 112 113 foreach ($tags as $id=>$entry) { 114 parent::add_to_cache('tag_map_' . $type,$id,$entry); 115 } 116 117 return true; 103 if ($ids) { 104 $type = self::validate_type($type); 105 $idlist = '(' . implode(',',$ids) . ')'; 106 107 $sql = "SELECT COUNT(`tag_map`.`id`) AS `count`,`tag`.`id`,`tag_map`.`object_id` FROM `tag_map` " . 108 "INNER JOIN `tag` ON `tag`.`id`=`tag_map`.`tag_id` " . 109 "WHERE `tag_map`.`object_type`='$type' AND `tag_map`.`object_id` IN $idlist " . 110 "GROUP BY `tag_map`.`object_id` ORDER BY `count` DESC"; 111 $db_results = Dba::query($sql); 112 113 while ($row = Dba::fetch_assoc($db_results)) { 114 $tags[$row['object_id']][] = $row; 115 } 116 117 foreach ($tags as $id=>$entry) { 118 parent::add_to_cache('tag_map_' . $type,$id,$entry); 119 } 120 121 return true; 122 } else { 123 return false; 124 } 118 125 119 126 } // build_map_cache -
trunk/lib/debug.lib.php
r1619 r1736 194 194 $current = ini_get('memory_limit'); 195 195 $current = substr($current_memory,0,strlen($current_memory)-1); 196 $new_limit = ($current+1 ) . "M";197 198 /* Bump it by one meg*/196 $new_limit = ($current+16) . "M"; 197 198 /* Bump it by 16 megs (for getid3)*/ 199 199 if (!ini_set(memory_limit,$new_limit)) { 200 200 return false; -
trunk/lib/init.php
r1731 r1736 268 268 if (Config::get('debug') == 'false' || Config::get('debug') == NULL) { 269 269 error_reporting(0); 270 } else { 271 error_reporting(E_ALL); 270 272 } 271 273 ?> -
trunk/templates/show_random_albums.inc.php
r1535 r1736 25 25 26 26 <?php 27 foreach ($albums as $album_id) { 28 $album = new Album($album_id); 29 $album->format(); 30 $name = '[' . $album->f_artist . '] ' . scrub_out($album->full_name); 27 if ($album_id) { 28 foreach ($albums as $album_id) { 29 $album = new Album($album_id); 30 $album->format(); 31 $name = '[' . $album->f_artist . '] ' . scrub_out($album->full_name); 31 32 ?> 32 33 <div class="random_album"> … … 48 49 </div> 49 50 50 <?php } ?> 51 <?php } // end foreach ?> 52 <?php } // end if album_id ?> 51 53 52 54 <?php show_box_bottom(); ?>
