diff options
author | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2008-08-08 05:15:34 +0000 |
---|---|---|
committer | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2008-08-08 05:15:34 +0000 |
commit | 73e70d7d9989e49fc7c34613bbcb1f5f339b3f2c (patch) | |
tree | 1fc9ffe3b964ef5c9e732215e007ae7c794d4507 /lib/class | |
parent | dda0815b08128ef66da98ab007ed1b57ac33fe50 (diff) | |
download | ampache-73e70d7d9989e49fc7c34613bbcb1f5f339b3f2c.tar.gz ampache-73e70d7d9989e49fc7c34613bbcb1f5f339b3f2c.tar.bz2 ampache-73e70d7d9989e49fc7c34613bbcb1f5f339b3f2c.zip |
fixed a long standing browsing issue where you could not browse two different things at the same time
Diffstat (limited to 'lib/class')
-rw-r--r-- | lib/class/browse.class.php | 44 | ||||
-rw-r--r-- | lib/class/update.class.php | 35 |
2 files changed, 72 insertions, 7 deletions
diff --git a/lib/class/browse.class.php b/lib/class/browse.class.php index c6446916..37e18630 100644 --- a/lib/class/browse.class.php +++ b/lib/class/browse.class.php @@ -40,6 +40,7 @@ class Browse { // Static Content, this is defaulted to false, if set to true then wen can't // apply any filters that would change the result set. public static $static_content = false; + private static $_cache = array(); /** @@ -216,6 +217,16 @@ class Browse { } // set_type /** + * get_type + * This returns the type of the browse we currently are using + */ + public static function get_type() { + + return self::$type; + + } // get_type + + /** * set_sort * This sets the current sort(s) */ @@ -341,8 +352,21 @@ class Browse { */ public static function get_saved() { - $objects = $_SESSION['browse']['save'][self::$type]; - + // See if we have it in the local cache first + if (is_array(self::$_cache['browse'][self::$type])) { + return self::$_cache['browse'][self::$type]; + } + + // If not then we're going to need to read from the database :( + $sid = session_id() . '::' . self::$type; + + $sql = "SELECT `data` FROM `tmp_browse` WHERE `sid`='$sid'"; + $db_results = Dba::read($sql); + + $row = Dba::fetch_assoc($db_results); + + $objects = unserialize($row['data']); + return $objects; } // get_saved @@ -795,7 +819,7 @@ class Browse { public static function show_objects($object_ids=false, $ajax=false) { $object_ids = $object_ids ? $object_ids : self::get_saved(); - + // Reset the total items self::$total_objects = count($object_ids); @@ -900,8 +924,17 @@ class Browse { */ public static function save_objects($object_ids) { - // save these objects - $_SESSION['browse']['save'][self::$type] = $object_ids; + // Saving these objects has two operations, one hold it in + // a local variable and then second hold it in a row in the tmp_browse + // table + self::$_cache['browse'][self::$type] = $object_ids; + + $sid = session_id() . '::' . self::$type; + $data = Dba::escape(serialize($object_ids)); + + $sql = "REPLACE INTO `tmp_browse` SET `data`='$data', `sid`='$sid'"; + $db_results = Dba::write($sql); + self::$total_objects = count($object_ids); return true; @@ -974,7 +1007,6 @@ class Browse { self::$simple_browse = make_bool($_SESSION['browse']['simple']); self::$static_content = make_bool($_SESSION['browse']['static']); - self::$type = $_SESSION['browse']['type']; self::$start = intval($_SESSION['browse'][self::$type]['start']); } // _auto_init diff --git a/lib/class/update.class.php b/lib/class/update.class.php index fc25cdd6..b56e51d8 100644 --- a/lib/class/update.class.php +++ b/lib/class/update.class.php @@ -284,7 +284,9 @@ class Update { $update_string = '- Remove Genre Field from song table.<br />' . '- Add user_catalog table for tracking user<-->catalog mappings.<br />' . - '- Alter user table to handle SHA2 passwords.<br />'; + '- Add tmp_browse to handle caching rather then session table.<br />'; + + $version[] = array('version' => '350002','description'=>$update_string); return $version; @@ -1365,5 +1367,36 @@ class Update { } // update_350001 + /** + * update_350002 + * This update adds in the browse_cache table that we use to hold peoples cached browse results + * rather then try to store everything in the session we split them out into one serilized array per + * row, per person. A little slow this way when browsing, but faster when now browsing and more flexible + */ + public static function update_350002() { + + $sql = "CREATE TABLE `tmp_browse` (`sid` varchar(128) collate utf8_unicode_ci NOT NULL,`data` longtext collate utf8_unicode_ci NOT NULL," . + " UNIQUE KEY `sid` (`sid`)) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci"; + $db_results = Dba::write($sql); + + $sql = "ALTER TABLE `tmp_browse` ADD INDEX ( `type` )"; + $db_results = Dba::write($sql); + + $sql = "ALTER TABLE `song` DROP `genre`"; + $db_results = Dba::write($sql); + + $sql = "CREATE TABLE `user_catalog` (`user` INT( 11 ) UNSIGNED NOT NULL ,`catalog` INT( 11 ) UNSIGNED NOT NULL ,`level` SMALLINT( 4 ) UNSIGNED NOT NULL DEFAULT '5', " . + "INDEX ( `user` )) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_unicode_ci"; + $db_results = Dba::write($sql); + + $sql = "ALTER TABLE `user_catalog` ADD INDEX ( `catalog` )"; + $db_results = Dba::write($sql); + + self::set_version('db_version','350002'); + + return true; + + } // update_350002 + } // end update class ?> |