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 | |
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
-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 | ||||
-rw-r--r-- | templates/show_artist_row.inc.php | 2 | ||||
-rw-r--r-- | templates/show_artists.inc.php | 3 | ||||
-rw-r--r-- | util.php | 30 |
7 files changed, 58 insertions, 30 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); diff --git a/templates/show_artist_row.inc.php b/templates/show_artist_row.inc.php index 00f2ac6e..b78216af 100644 --- a/templates/show_artist_row.inc.php +++ b/templates/show_artist_row.inc.php @@ -33,7 +33,7 @@ <?php echo get_user_icon('batch_download','',_('Batch Download')); ?> </a> <?php } ?> -<?php if ($GLOBALS['user']->has_access(50)) { ?> +<?php if (Access::check('interface','50')) { ?> <?php echo Ajax::button('?action=show_edit_object&type=artist&id=' . $artist->id,'edit',_('Edit'),'edit_artist_' . $artist->id); ?> <?php } ?> </td> diff --git a/templates/show_artists.inc.php b/templates/show_artists.inc.php index 9e80363d..13c5e307 100644 --- a/templates/show_artists.inc.php +++ b/templates/show_artists.inc.php @@ -40,6 +40,9 @@ $web_path = Config::get('web_path'); <th class="cel_action"> <?php echo _('Action'); ?> </th> </tr> <?php +// Cache the ratings we are going to use +if (Config::get('ratings')) { Rating::build_cache('artist',$object_ids); } + /* Foreach through every artist that has been passed to us */ foreach ($object_ids as $artist_id) { $artist = new Artist($artist_id); @@ -1,7 +1,7 @@ <?php /* - Copyright (c) Ampache.org + Copyright (c) 2001 - 2007 ampache.org All rights reserved. This program is free software; you can redistribute it and/or @@ -18,7 +18,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -define('NO_SESSION','1'); require_once 'lib/init.php'; header("Expires: Tuesday, 27 Mar 1984 05:00:00 GMT"); @@ -26,29 +25,16 @@ header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Pragma: no-cache"); -$session_name = Config::get('session_name'); - -if (!vauth::session_exists('interface',$_COOKIE[$session_name])) { - debug_event('Util','Invalid Session:' . $_COOKIE[$session_name] . 'for session ' . $session_name,'1'); - exit; -} - -$data = vauth::read($_COOKIE[$session_name]); - -preg_match_all("/(\w+)\|(a\:[^\|]+;})/",$data,$matches); - -foreach ($matches['1'] as $key=>$value) { - if ($value == 'iframe') { - $data = unserialize($matches['2'][$key]); - } -} - // This is a little bit of a special file, it takes the // content of $_SESSION['iframe']['target'] and does a header // redirect to that spot! -if (isset($data['target'])) { - $target = $data['target']; - unset($data['target']); +if (isset($_SESSION['iframe']['target'])) { + $target = $_SESSION['iframe']['target']; + unset($_SESSION['iframe']['target']); header("Location: " . $target); } +else { + // Prevent the update query as it's pointless + define('NO_SESSION_UPDATE','1'); +} ?> |