diff --git a/mod/chat/db/mysql.php b/mod/chat/db/mysql.php index 76608fe3de3..bea62ca47ae 100644 --- a/mod/chat/db/mysql.php +++ b/mod/chat/db/mysql.php @@ -37,6 +37,22 @@ function chat_upgrade($oldversion) { modify_database("", "INSERT INTO prefix_log_display VALUES ('chat', 'talk', 'chat', 'name');"); } + if ($oldversion < 2004111200) { + execute_sql('ALTER TABLE prefix_chat DROP INDEX `course`;',false); + execute_sql('ALTER TABLE prefix_chat_messages DROP INDEX `chatid`;',false); + execute_sql('ALTER TABLE prefix_chat_messages DROP INDEX `userid`;',false); + execute_sql('ALTER TABLE prefix_chat_messages DROP INDEX `groupid`;',false); + execute_sql('ALTER TABLE prefix_chat_users DROP INDEX `chatid`;',false); + execute_sql('ALTER TABLE prefix_chat_users DROP INDEX `groupid`;',false); + + modify_database('','ALTER TABLE prefix_chat ADD INDEX `course` (`course`);'); + modify_database('','ALTER TABLE prefix_chat_messages ADD INDEX `chatid` (`chatid`);'); + modify_database('','ALTER TABLE prefix_chat_messages ADD INDEX `userid` (`userid`);'); + modify_database('','ALTER TABLE prefix_chat_messages ADD INDEX `groupid` (`groupid`);'); + modify_database('','ALTER TABLE prefix_chat_users ADD INDEX `chatid` (`chatid`);'); + modify_database('','ALTER TABLE prefix_chat_users ADD INDEX `groupid` (`groupid`);'); + } + return true; } diff --git a/mod/chat/db/mysql.sql b/mod/chat/db/mysql.sql index 6efe107078d..68365a8dd80 100644 --- a/mod/chat/db/mysql.sql +++ b/mod/chat/db/mysql.sql @@ -12,7 +12,8 @@ CREATE TABLE `prefix_chat` ( `chattime` int(10) unsigned NOT NULL default '0', `schedule` int(4) NOT NULL default '0', `timemodified` int(10) unsigned NOT NULL default '0', - PRIMARY KEY (`id`) + PRIMARY KEY (`id`), + KEY `course` (`course`) ) TYPE=MyISAM COMMENT='Each of these is a chat room'; # -------------------------------------------------------- @@ -29,7 +30,10 @@ CREATE TABLE `prefix_chat_messages` ( `message` text NOT NULL, `timestamp` int(10) unsigned NOT NULL default '0', PRIMARY KEY (`id`), - KEY `timemodifiedchat` (`timestamp`,`chatid`) + KEY `timemodifiedchat` (`timestamp`,`chatid`), + KEY `chatid` (`chatid`), + KEY `userid` (`userid`), + KEY `groupid` (`groupid`) ) TYPE=MyISAM COMMENT='Stores all the actual chat messages'; # -------------------------------------------------------- @@ -50,7 +54,9 @@ CREATE TABLE `prefix_chat_users` ( `sid` varchar(32) NOT NULL default '', PRIMARY KEY (`id`), KEY `userid` (`userid`), - KEY `lastping` (`lastping`) + KEY `lastping` (`lastping`), + KEY `chatid` (`chatid`), + KEY `groupid` (`groupid`) ) TYPE=MyISAM COMMENT='Keeps track of which users are in which chat rooms'; diff --git a/mod/chat/db/postgres7.php b/mod/chat/db/postgres7.php index 311f95fe62b..a726b9b04d9 100644 --- a/mod/chat/db/postgres7.php +++ b/mod/chat/db/postgres7.php @@ -20,6 +20,28 @@ function chat_upgrade($oldversion) { modify_database("", "INSERT INTO prefix_log_display VALUES ('chat', 'talk', 'chat', 'name');"); } + if ($oldversion < 2004111200) { //drop them first to avoid collisions with upgrades from 1.4.2+ + execute_sql('DROP INDEX prefix_chat_course_idx;',false); + execute_sql('DROP INDEX prefix_chat_messages_chatid_idx;',false); + execute_sql('DROP INDEX prefix_chat_messages_userid_idx;',false); + execute_sql('DROP INDEX prefix_chat_messages_groupid_idx;',false); + execute_sql('DROP INDEX prefix_chat_messages_timemodifiedchatid_idx;',false); + execute_sql('DROP INDEX prefix_chat_users_chatid_idx;',false); + execute_sql('DROP INDEX prefix_chat_users_userid_idx;',false); + execute_sql('DROP INDEX prefix_chat_users_groupid_idx;',false); + execute_sql('DROP INDEX prefix_chat_users_lastping_idx;',false); + + modify_database('','CREATE INDEX prefix_chat_course_idx ON prefix_chat(course);'); + modify_database('','CREATE INDEX prefix_chat_messages_chatid_idx ON prefix_chat_messages (chatid);'); + modify_database('','CREATE INDEX prefix_chat_messages_userid_idx ON prefix_chat_messages (userid);'); + modify_database('','CREATE INDEX prefix_chat_messages_groupid_idx ON prefix_chat_messages (groupid);'); + modify_database('','CREATE INDEX prefix_chat_messages_timemodifiedchatid_idx ON prefix_chat_messages(timestamp,chatid);'); + modify_database('','CREATE INDEX prefix_chat_users_chatid_idx ON prefix_chat_users (chatid);'); + modify_database('','CREATE INDEX prefix_chat_users_userid_idx ON prefix_chat_users (userid);'); + modify_database('','CREATE INDEX prefix_chat_users_groupid_idx ON prefix_chat_users (groupid);'); + modify_database('','CREATE INDEX prefix_chat_users_lastping_idx ON prefix_chat_users (lastping);'); + } + return true; } diff --git a/mod/chat/db/postgres7.sql b/mod/chat/db/postgres7.sql index b77d1187f1d..c1928e4af97 100644 --- a/mod/chat/db/postgres7.sql +++ b/mod/chat/db/postgres7.sql @@ -14,6 +14,9 @@ CREATE TABLE prefix_chat ( timemodified INTEGER NOT NULL default '0', PRIMARY KEY (id) ); + +CREATE INDEX prefix_chat_course_idx ON prefix_chat(course); + # -------------------------------------------------------- # @@ -30,6 +33,12 @@ CREATE TABLE prefix_chat_messages ( timestamp integer NOT NULL default '0', PRIMARY KEY (id) ); + +CREATE INDEX prefix_chat_messages_chatid_idx ON prefix_chat_messages (chatid); +CREATE INDEX prefix_chat_messages_userid_idx ON prefix_chat_messages (userid); +CREATE INDEX prefix_chat_messages_groupid_idx ON prefix_chat_messages (groupid); +CREATE INDEX prefix_chat_messages_timemodifiedchatid_idx ON prefix_chat_messages(timestamp,chatid); + # -------------------------------------------------------- # @@ -50,6 +59,10 @@ CREATE TABLE prefix_chat_users ( PRIMARY KEY (id) ); +CREATE INDEX prefix_chat_users_chatid_idx ON prefix_chat_users (chatid); +CREATE INDEX prefix_chat_users_userid_idx ON prefix_chat_users (userid); +CREATE INDEX prefix_chat_users_groupid_idx ON prefix_chat_users (groupid); +CREATE INDEX prefix_chat_users_lastping_idx ON prefix_chat_users (lastping); INSERT INTO prefix_log_display VALUES ('chat', 'view', 'chat', 'name'); INSERT INTO prefix_log_display VALUES ('chat', 'add', 'chat', 'name'); diff --git a/mod/chat/version.php b/mod/chat/version.php index f3bc17e9549..923d476740d 100644 --- a/mod/chat/version.php +++ b/mod/chat/version.php @@ -5,7 +5,7 @@ /// This fragment is called by moodle_needs_upgrading() and /admin/index.php ///////////////////////////////////////////////////////////////////////////////// -$module->version = 2004060400; // The (date) version of this module +$module->version = 2004121100; // The (date) version of this module $module->requires = 2004052505; // Requires this Moodle version $module->cron = 300; // How often should cron check this module (seconds)?