diff options
author | Tim Almdal <tnalmdal@shaw.ca> | 2009-07-30 01:55:56 +0800 |
---|---|---|
committer | Tim Almdal <tnalmdal@shaw.ca> | 2009-07-30 01:59:07 +0800 |
commit | ead6a61d9e96d37ca3a0aecb93d18755099e341c (patch) | |
tree | 7dab5b22d8e673f79b8f8e9aec642dc5bca81fe4 /modules/gallery/helpers | |
parent | eb90fc9e63e35e1131f19204a370fe711f5ecc01 (diff) |
Fix for ticket #576
Add a weight index to the item table and changed the retrieval of the maximum
weight to select weight from items order by weight desc limit 1.
Upgrades the gallery module to version 10
Signed-off-by: Tim Almdal <tnalmdal@shaw.ca>
Diffstat (limited to 'modules/gallery/helpers')
-rw-r--r-- | modules/gallery/helpers/gallery_installer.php | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/modules/gallery/helpers/gallery_installer.php b/modules/gallery/helpers/gallery_installer.php index 760bec31..2322110e 100644 --- a/modules/gallery/helpers/gallery_installer.php +++ b/modules/gallery/helpers/gallery_installer.php @@ -98,9 +98,20 @@ class gallery_installer { PRIMARY KEY (`id`), KEY `parent_id` (`parent_id`), KEY `type` (`type`), - KEY `random` (`rand_key`)) + KEY `random` (`rand_key`), + KEY `weight` (`weight` DESC)) ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + $db->query("DELIMITER | + CREATE TRIGGER setweight BEFORE INSERT ON {items} + FOR EACH ROW BEGIN + DECLARE new_weight int(9); + SELECT weight+1 FROM {items} + ORDER BY weight LIMIT 1 INTO new_weight; + SET NEW.weight = new_weight; + END;| + DELIMITER ;"); + $db->query("CREATE TABLE {logs} ( `id` int(9) NOT NULL auto_increment, `category` varchar(64) default NULL, @@ -329,7 +340,13 @@ class gallery_installer { $db->query("ALTER TABLE {items} CHANGE COLUMN `right` `right_ptr` INT(9) NOT NULL;"); module::set_version("gallery", $version = 9); } - } + + if ($version == 9) { + $db->query("ALTER TABLE {items} ADD KEY `weight` (`weight` DESC);"); + + module::set_version("gallery", $version = 10); + } +} static function uninstall() { $db = Database::instance(); |