Changeset 1545
- Timestamp:
- 05/11/08 22:58:17 (8 months ago)
- Location:
- trunk
- Files:
-
- 16 modified
-
browse.php (modified) (3 diffs)
-
docs/CHANGELOG (modified) (1 diff)
-
docs/README (modified) (1 diff)
-
lib/class/album.class.php (modified) (5 diffs)
-
lib/class/artist.class.php (modified) (4 diffs)
-
lib/class/browse.class.php (modified) (8 diffs)
-
lib/class/dba.class.php (modified) (4 diffs)
-
lib/class/localplay.abstract.php (modified) (1 diff)
-
lib/class/rating.class.php (modified) (3 diffs)
-
lib/class/song.class.php (modified) (7 diffs)
-
lib/class/tagcloud.class.php (modified) (5 diffs)
-
lib/class/update.class.php (modified) (2 diffs)
-
lib/class/user.class.php (modified) (4 diffs)
-
lib/init.php (modified) (2 diffs)
-
templates/footer.inc.php (modified) (1 diff)
-
templates/show_songs.inc.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/browse.php
r1543 r1545 57 57 Browse::set_sort('name','ASC'); 58 58 $album_ids = Browse::get_objects(); 59 Album::build_cache($album_ids); 59 60 Browse::show_objects($album_ids); 60 61 break; … … 62 63 Browse::set_sort('name','ASC'); 63 64 $artist_ids = Browse::get_objects(); 65 Artist::build_cache($artist_ids); 64 66 Browse::show_objects($artist_ids); 65 67 break; … … 72 74 Browse::set_sort('title','ASC'); 73 75 $song_ids = Browse::get_objects(); 76 Song::build_cache($song_ids); 74 77 Browse::show_objects($song_ids); 75 78 break; -
trunk/docs/CHANGELOG
r1538 r1545 2 2 --------- Ampache -- CHANGELOG --------- 3 3 -------------------------------------------------------------------------- 4 5 -------------------------------------------------------------------------- 6 v.3.5-Alpha1 7 - Upped Minimum requirements to Mysql 5.x 8 - Add codeunde1load's Web 2.0 style tag patch 9 - Fixed typo in e-mail From: name (Thx Xgizzmo) 10 - Fixed typo in browse auto_init() which could cause ampache to not 11 remember your start point in some situations. (Thx Xgizzmo) 4 12 5 13 -------------------------------------------------------------------------- -
trunk/docs/README
r1518 r1545 121 121 PHP5 ICONV 122 122 PHP5 ZLIB support (recommended) 123 MySQL >= 4.1+ http://www.mysql.com123 MySQL >= 5.x+ http://www.mysql.com 124 124 125 125 3. Setting Up -
trunk/lib/class/album.class.php
r1543 r1545 25 25 * it is related to the album table in the database. 26 26 */ 27 class Album {27 class Album extends database_object { 28 28 29 29 /* Variables from DB */ … … 51 51 * get any of the counts. 52 52 */ 53 public function __construct($album_id='') { 54 55 if (!$album_id) { return false; } 53 public function __construct($id='') { 54 55 if (!$id) { return false; } 56 56 57 57 58 /* Assign id for use in get_info() */ 58 $this->id = intval($ album_id);59 $this->id = intval($id); 59 60 60 61 /* Get the information from the db */ … … 71 72 return true; 72 73 73 } // constructor74 } // constructor 74 75 75 76 /** … … 91 92 92 93 } // construct_from_array 93 public static function build_cache($ids, $fields='*') { 94 $idlist = '(' . implode(',', $ids) . ')'; 95 $sql = "SELECT $fields FROM album WHERE id in $idlist"; 96 $db_results = Dba::query($sql); 97 global $album_cache; 98 $album_cache = array(); 99 while ($results = Dba::fetch_assoc($db_results)) { 100 $album_cache[intval($results['id'])] = $results; 101 } 102 } 94 95 /** 96 * build_cache 97 * This takes an array of object ids and caches all of their information 98 * with a single query 99 */ 100 public static function build_cache($ids) { 101 $idlist = '(' . implode(',', $ids) . ')'; 102 103 $sql = "SELECT * FROM `album` WHERE `id` IN $idlist"; 104 $db_results = Dba::query($sql); 105 106 while ($row = Dba::fetch_assoc($db_results)) { 107 parent::add_to_cache('album',$row['id'],$row); 108 } 109 110 } // build_cache 111 103 112 /** 104 113 * _get_info … … 107 116 */ 108 117 private function _get_info() { 109 global $album_cache; 110 if (isset($album_cache[intval($this->id)])) 111 return $album_cache[intval($this->id)]; 118 119 $id = intval($this->id); 120 121 if (parent::is_cached('album',$id)) { 122 return parent::get_from_cache('album',$id); 123 } 124 112 125 // Just get the album information 113 $sql = "SELECT * FROM `album` WHERE `id`=' " . $this->id . "'";126 $sql = "SELECT * FROM `album` WHERE `id`='$id'"; 114 127 $db_results = Dba::query($sql); 115 128 116 129 $results = Dba::fetch_assoc($db_results); 130 131 // Cache the object 132 parent::add_to_cache('album',$id,$results); 117 133 118 134 return $results; -
trunk/lib/class/artist.class.php
r1543 r1545 2 2 /* 3 3 4 Copyright (c) 2001 - 2008Ampache.org4 Copyright (c) Ampache.org 5 5 All rights reserved. 6 6 … … 23 23 * Artist Class 24 24 */ 25 class Artist {25 class Artist extends database_object { 26 26 27 27 /* Variables from DB */ … … 77 77 78 78 } // construct_from_array 79 public static function build_cache($ids, $fields='*') { 80 $idlist = '(' . implode(',', $ids) . ')'; 81 $sql = "SELECT $fields FROM artist WHERE id in $idlist"; 82 $db_results = Dba::query($sql); 83 global $artist_cache; 84 $artist_cache = array(); 85 while ($results = Dba::fetch_assoc($db_results)) { 86 $artist_cache[intval($results['id'])] = $results; 87 } 88 } 79 80 /** 81 * this attempts to build a cache of the data from the passed albums all in one query 82 */ 83 public static function build_cache($ids) { 84 $idlist = '(' . implode(',', $ids) . ')'; 85 86 $sql = "SELECT * FROM `artist` WHERE `id` IN $idlist"; 87 $db_results = Dba::query($sql); 88 89 while ($row = Dba::fetch_assoc($db_results)) { 90 parent::add_to_cache('artist',$row['id'],$row); 91 } 92 93 } // build_cache 94 89 95 /** 90 96 * _get_info … … 92 98 */ 93 99 private function _get_info() { 94 global $artist_cache; 95 if (isset($artist_cache[intval($this->id)])) 96 return $artist_cache[intval($this->id)]; 100 101 $id = intval($this->id); 102 103 if (parent::is_cached('artist',$id)) { 104 return parent::get_from_cache('artist',$id); 105 } 106 97 107 /* Grab the basic information from the catalog and return it */ 98 $sql = "SELECT * FROM artist WHERE id=' " . Dba::escape($this->id) . "'";108 $sql = "SELECT * FROM artist WHERE id='$id'"; 99 109 $db_results = Dba::query($sql); 100 110 101 111 $results = Dba::fetch_assoc($db_results); 112 113 parent::add_to_cache('artist',$id,$results); 102 114 103 115 return $results; -
trunk/lib/class/browse.class.php
r1543 r1545 73 73 break; 74 74 case 'tag': 75 //var_dump($value); 76 if (is_array($value)) 77 $_SESSION['browse']['filter'][$key] = $value; 78 else if (is_numeric($value)) 79 $_SESSION['browse']['filter'][$key] = 80 array($value); 81 else 82 $_SESSION['browse']['filter'][$key] = array(); 83 break; 84 case 'artist': 85 case 'album': 86 $_SESSION['browse']['filter'][$key] = $value; 87 break; 75 if (is_array($value)) { 76 $_SESSION['browse']['filter'][$key] = $value; 77 } 78 elseif (is_numeric($value)) { 79 $_SESSION['browse']['filter'][$key] = array($value); 80 } 81 else { 82 $_SESSION['browse']['filter'][$key] = array(); 83 } 84 break; 85 case 'artist': 86 case 'album': 87 $_SESSION['browse']['filter'][$key] = $value; 88 break; 88 89 case 'min_count': 89 90 … … 94 95 case 'alpha_match': 95 96 if (self::$static_content) { return false; } 96 //if ($value == _('All')) { $value = ''; }97 97 $_SESSION['browse']['filter'][$key] = $value; 98 98 break; … … 365 365 366 366 $results = array(); 367 while ($data = Dba::fetch_assoc($db_results)) 368 $results[] = $data; 369 var_dump($results); 367 while ($data = Dba::fetch_assoc($db_results)) { 368 $results[] = $data; 369 } 370 370 371 $results = self::post_process($results); 371 372 $filtered = array(); … … 507 508 508 509 $sql = $sql . $order_sql; 509 var_dump($sql);510 510 return $sql; 511 511 512 512 } // get_sql 513 private static function post_process($results) 514 { 515 $tags = $_SESSION['browse']['filter']['tag']; 516 if (!is_array($tags) || sizeof($tags) < 2) 517 return $results; 518 $cnt = sizeof($tags); 519 $ar = array(); 520 foreach($results as $row) 521 $ar[$row['id']]++; 522 $res = array(); 523 foreach($ar as $k=>$v) 524 if ($v >= $cnt) 525 $res[] = array('id' => $k); 526 return $res; 527 } 513 514 /** 515 * post_process 516 * This does some additional work on the results that we've received before returning them 517 */ 518 private static function post_process($results) { 519 520 $tags = $_SESSION['browse']['filter']['tag']; 521 522 if (!is_array($tags) || sizeof($tags) < 2) { 523 return $results; 524 } 525 $cnt = sizeof($tags); 526 $ar = array(); 527 528 foreach($results as $row) { 529 $ar[$row['id']]++; 530 } 531 532 $res = array(); 533 534 foreach($ar as $k=>$v) { 535 if ($v >= $cnt) { 536 $res[] = array('id' => $k); 537 } 538 } // end foreach 539 540 return $res; 541 542 } // post_process 543 528 544 /** 529 545 * sql_filter … … 541 557 || $_SESSION['browse']['type'] == 'album' 542 558 )) { 543 //var_dump($value);544 559 if (is_array($value) && sizeof($value)) 545 560 $vals = '(' . implode(',',$value) . ')'; … … 797 812 // Load any additional object we need for this 798 813 $extra_objects = self::get_supplemental_objects(); 799 var_dump($object_ids);800 814 foreach ($extra_objects as $class_name => $id) { 801 815 ${$class_name} = new $class_name($id); … … 806 820 array('artist','album','song'))) { 807 821 $tagcloudHead = "Matching tags"; 808 $tagcloudList = 809 TagCloud::get_tags($_SESSION['browse']['type'], $all_ids); 822 $tagcloudList = TagCloud::get_tags($_SESSION['browse']['type'], $all_ids); 810 823 require_once Config::get('prefix') . '/templates/show_tagcloud.inc.php'; 811 824 } 812 Dba::show_profile();825 813 826 Ajax::start_container('browse_content'); 814 827 // Switch on the type of browsing we're doing … … 966 979 public static function set_filter_from_request($r) 967 980 { 968 //var_dump($r);969 981 foreach ($r as $k=>$v) { 970 982 //reinterpret v as a list of int 971 983 $vl = explode(',', $v); 972 //var_dump($vl);973 984 $ok = 1; 974 985 foreach($vl as $i) { -
trunk/lib/class/dba.class.php
r1543 r1545 33 33 class Dba { 34 34 35 public static $stats = array('query'=>0); 36 35 37 private static $_default_db; 36 37 38 private static $_sql; 38 39 private static $config; … … 54 55 */ 55 56 public static function query($sql) { 56 /*if ($_REQUEST['profiling']) { 57 $sql = rtrim($sql, '; '); 58 $sql .= ' SQL_NO_CACHE'; 59 }*/ 57 60 58 // Run the query 61 59 $resource = mysql_query($sql,self::dbh()); … … 64 62 // Save the query, to make debug easier 65 63 self::$_sql = $sql; 64 self::$stats['query']++; 66 65 67 66 return $resource; … … 201 200 } // _connect 202 201 202 /** 203 * show_profile 204 * This function is used for debug, helps with profiling 205 */ 203 206 public static function show_profile() { 204 if ($_REQUEST['profiling']) { 205 print '<br/>Profiling data: <br/>'; 206 $res = Dba::query('show profiles'); 207 print '<table>'; 208 while ($r = Dba::fetch_row($res)) { 209 print '<tr><td>' . implode('</td><td>', $r) . '</td></tr>'; 210 } 211 print '</table>'; 212 } 213 } 207 208 if (Config::get('sql_profiling')) { 209 print '<br/>Profiling data: <br/>'; 210 $res = Dba::query('show profiles'); 211 print '<table>'; 212 while ($r = Dba::fetch_row($res)) { 213 print '<tr><td>' . implode('</td><td>', $r) . '</td></tr>'; 214 } 215 print '</table>'; 216 } 217 } // show_profile 218 214 219 /** 215 220 * dbh -
trunk/lib/class/localplay.abstract.php
r1405 r1545 2 2 /* 3 3 4 Copyright (c) 2001 - 2007Ampache.org4 Copyright (c) Ampache.org 5 5 All Rights Reserved 6 6 -
trunk/lib/class/rating.class.php
r1543 r1545 25 25 * to track ratings for songs, albums and artists. 26 26 */ 27 class Rating {27 class Rating extends database_object { 28 28 29 29 /* Provided vars */ … … 57 57 58 58 } // Constructor 59 60 /** 61 * build_cache 62 * This attempts to get everything we'll need for this page load in a single query, saving 63 * the connection overhead 64 * //FIXME: Improve logic so that misses get cached as average 65 */ 59 66 public static function build_cache($type, $ids) { 60 $idlist = '(' . implode(',', $ids) . ')'; 61 $sql = "SELECT `rating`, object_id FROM `rating` WHERE `user`='$user_id' AND `object_id` in $idlist AND `object_type`='$type'"; 62 global $rating_cache; 63 $rating_cache = array(); 64 $db_results = Dba::query($sql); 65 while ($results = Dba::fetch_assoc($db_results)) { 66 $rating_cache[intval($results['object_id'])] = $results; 67 } 68 } 67 68 $user_id = Dba::escape($GLOBALS['user']->id); 69 70 $idlist = '(' . implode(',', $ids) . ')'; 71 $sql = "SELECT `rating`, `object_id` FROM `rating` WHERE `user`='$user_id' AND `object_id` IN $idlist " . 72 "AND `object_type`='$type'"; 73 $db_results = Dba::query($sql); 74 75 while ($row = Dba::fetch_assoc($db_results)) { 76 $rating[$row['id']] = $row['rating']; 77 } 78 79 $user_cache_name = 'rating_' . $type . '_user'; 80 81 foreach ($ids as $id) { 82 parent::add_to_cache($user_cache_name,$id,intval($rating[$id])); 83 } // end foreach 84 85 86 } // build_cache 87 69 88 /** 70 89 * get_user … … 73 92 */ 74 93 public function get_user($user_id) { 75 global $rating_cache; 76 if (isset($rating_cache[intval($this->id)])); 77 return $rating_cache[intval($this->id)]['rating']; 78 $user_id = Dba::escape($user_id); 79 80 $sql = "SELECT `rating` FROM `rating` WHERE `user`='$user_id' AND `object_id`='$this->id' AND `object_type`='$this->type'"; 94 95 $id = intval($this->id); 96 97 if (parent::is_cached('rating_' . $this->type . '_user',$id)) { 98 return parent::get_from_cache('rating_' . $this->type . '_user',$id); 99 } 100 101 $user_id = Dba::escape($user_id); 102 103 $sql = "SELECT `rating` FROM `rating` WHERE `user`='$user_id' AND `object_id`='$id' AND `object_type`='$this->type'"; 81 104 $db_results = Dba::query($sql); 82 105 83 106 $results = Dba::fetch_assoc($db_results); 107 108 parent::add_to_cache('rating_' . $this->type . '_user',$id,$results['rating']); 84 109 85 110 return $results['rating']; -
trunk/lib/class/song.class.php
r1543 r1545 20 20 */ 21 21 22 class Song {22 class Song extends database_object { 23 23 24 24 /* Variables from DB */ … … 53 53 public function __construct($id='') { 54 54 55 if (!$id) { return false; } 56 55 57 /* Assign id for use in get_info() */ 56 58 $this->id = intval($id); 57 58 if (!$this->id) { return false; }59 59 60 60 /* Get the information from the db */ … … 71 71 72 72 } // constructor 73 public static function build_cache($ids) 74 { 75 $idlist = '(' . implode(',', $ids) . ')'; 73 74 /** 75 * build_cache 76 * This attempts to reduce # of queries by asking for everything in the browse 77 * all at once and storing it in the cache, this can help if the db connection 78 * is the slow point 79 */ 80 public static function build_cache($song_ids) { 81 82 $idlist = '(' . implode(',', $song_ids) . ')'; 76 83 77 // Song data cache 78 $sql = "SELECT song.id,file,catalog,album,year,artist,". 79 "title,bitrate,rate,mode,size,time,track,genre,played,song.enabled,update_time,". 80 "addition_time FROM `song` WHERE `song`.`id` in 81 $idlist"; 82 $db_results = Dba::query($sql); 83 global $song_cache; 84 $song_cache = array(); 85 while ($results = Dba::fetch_assoc($db_results)) 86 { 87 $song_cache[intval($results['id'])] = $results; 88 } 84 // Song data cache 85 $sql = "SELECT song.id,file,catalog,album,year,artist,". 86 "title,bitrate,rate,mode,size,time,track,genre,played,song.enabled,update_time,". 87 "addition_time FROM `song` WHERE `song`.`id` IN 88 $idlist"; 89 $db_results = Dba::query($sql); 89 90 90 // Extra sound data cache 91 global $song_data_cache; 92 $song_data_cache = array(); 93 $sql = "SELECT * FROM song_data WHERE song_id in $idlist"; 94 $db_results = Dba::query($sql); 95 while ($results = Dba::fetch_assoc($db_results)) 96 { 97 $song_data_cache[intval($results['song_id'])] = $results; 98 } 99 100 // Get all artist, album, genre ids. 101 $artists = array(); 102 $albums = array(); 103 $genre = array(); 104 foreach ($song_cache as $i) 105 { 106 $artists[$i['artist']] = 1; 107 $albums[$i['album']] = 1; 108 $genre[$i['genre']] = 1; 109 } 110
