From ead6a61d9e96d37ca3a0aecb93d18755099e341c Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Thu, 30 Jul 2009 01:55:56 +0800 Subject: 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 --- modules/gallery/helpers/gallery_installer.php | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'modules/gallery/helpers') 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(); -- cgit v1.2.3