diff options
author | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2008-05-26 22:07:26 +0000 |
---|---|---|
committer | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2008-05-26 22:07:26 +0000 |
commit | 5fce261ae2a1fad5a6f1e437a5245a7b1bf981f3 (patch) | |
tree | a7607908104b23e84c4793a0da1a4c79a11258f9 /lib | |
parent | fdc509c5c4e2e2256585889ccf0a11a1712f1316 (diff) | |
download | ampache-5fce261ae2a1fad5a6f1e437a5245a7b1bf981f3.tar.gz ampache-5fce261ae2a1fad5a6f1e437a5245a7b1bf981f3.tar.bz2 ampache-5fce261ae2a1fad5a6f1e437a5245a7b1bf981f3.zip |
more improvements to the caching system, removed ugly hack from last night on util
Diffstat (limited to 'lib')
-rw-r--r-- | lib/class/browse.class.php | 5 | ||||
-rw-r--r-- | lib/class/song.class.php | 9 | ||||
-rw-r--r-- | lib/class/tag.class.php | 37 | ||||
-rw-r--r-- | lib/class/vauth.class.php | 2 |
4 files changed, 46 insertions, 7 deletions
diff --git a/lib/class/browse.class.php b/lib/class/browse.class.php index 932b4064..58fabccf 100644 --- a/lib/class/browse.class.php +++ b/lib/class/browse.class.php @@ -815,11 +815,6 @@ class Browse { ${$class_name} = new $class_name($id); } - if (!$ajax && Tag::validate_type($_SESSION['browse']['type'])) { - $tagcloudList = Tag::get_many_tags($_SESSION['browse']['type'], $all_ids); - require_once Config::get('prefix') . '/templates/show_tagcloud.inc.php'; - } - Ajax::start_container('browse_content'); // Switch on the type of browsing we're doing switch ($_SESSION['browse']['type']) { diff --git a/lib/class/song.class.php b/lib/class/song.class.php index f38c7985..e9e92de6 100644 --- a/lib/class/song.class.php +++ b/lib/class/song.class.php @@ -98,6 +98,7 @@ class Song extends database_object { Artist::build_cache($artists); Album::build_cache($albums); Tag::build_cache($tags); + Tag::build_map_cache('song',$song_ids); // Build a cache for the song's extended table $sql = "SELECT * FROM `song_data` WHERE `song_id` IN $idlist"; @@ -669,6 +670,8 @@ class Song extends database_object { // Get the top tags $tags = Tag::get_top_tags('song',$this->id); + + $this->f_tags = ''; foreach ($tags as $tag_id) { $tag = new Tag($tag_id); $this->f_tags .= $tag->name . ', '; @@ -816,7 +819,11 @@ class Song extends database_object { /* Account for retarded players */ if ($this->type == 'flac') { $type = 'ogg'; } - $this->format(); + // Only reformat if we need to + if (!isset($this->f_title)) { + $this->format(); + } + $song_name = rawurlencode($this->f_artist_full . " - " . $this->title . "." . $type); $web_path = Config::get('web_path'); diff --git a/lib/class/tag.class.php b/lib/class/tag.class.php index ff0bfa9c..3499cd94 100644 --- a/lib/class/tag.class.php +++ b/lib/class/tag.class.php @@ -110,9 +110,39 @@ class Tag extends database_object { parent::add_to_cache('tag',$row['id'],$row); } + return true; + } // build_cache /** + * build_map_cache + * This builds a cache of the mappings for the specified object, no limit is given + */ + public static function build_map_cache($type,$ids) { + + $type = self::validate_type($type); + $idlist = '(' . implode(',',$ids) . ')'; + + $sql = "SELECT COUNT(`tag_map`.`id`) AS `count`,`tag`.`id`,`tag_map`.`object_id` FROM `tag_map` " . + "INNER JOIN `tag` ON `tag`.`id`=`tag_map`.`tag_id` " . + "WHERE `tag_map`.`object_type`='$type' AND `tag_map`.`object_id` IN $idlist " . + "GROUP BY `tag_map`.`object_id` ORDER BY `count` DESC"; + $db_results = Dba::query($sql); + + while ($row = Dba::fetch_assoc($db_results)) { + $tags[$row['object_id']][] = $row; + } + + + foreach ($tags as $id=>$entry) { + parent::add_to_cache('tag_map_' . $type,$id,$entry); + } + + return true; + + } // build_map_cache + + /** * has_object * This checks to see if the current tag element has the specified object * of the specified type @@ -249,13 +279,18 @@ return array(); public static function get_top_tags($type,$object_id,$limit='2') { $type = self::validate_type($type); + + if (parent::is_cached('tag_map_' . $type,$object_id)) { + return parent::get_from_cache('tag_map_' . $type,$object_id); + } + $object_id = intval($object_id); $limit = intval($limit); $sql = "SELECT COUNT(`tag_map`.`id`) AS `count`,`tag`.`id` FROM `tag_map` " . "INNER JOIN `tag` ON `tag`.`id`=`tag_map`.`tag_id` " . "WHERE `tag_map`.`object_type`='$type' AND `tag_map`.`object_id`='$object_id' " . - "GROUP BY `tag_map`.`tag_id` ORDER BY `count` LIMIT $limit"; + "GROUP BY `tag_map`.`object_id` ORDER BY `count` DESC LIMIT $limit"; $db_results = Dba::query($sql); $results = array(); diff --git a/lib/class/vauth.class.php b/lib/class/vauth.class.php index c509b786..400edf6d 100644 --- a/lib/class/vauth.class.php +++ b/lib/class/vauth.class.php @@ -88,6 +88,8 @@ class vauth { */ public static function write($key,$value) { + if (NO_SESSION_UPDATE == '1') { return true; } + $length = Config::get('session_length'); $value = Dba::escape($value); $key = Dba::escape($key); |