From f5c6e8db1dea90cd2d54bd32a78d89a24d98a3cb Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Fri, 4 Apr 2014 11:37:17 +0800 Subject: [PATCH] MDL-18598 forum: redefine index to allow faster cron jobs --- mod/forum/db/install.xml | 6 +++--- mod/forum/db/upgrade.php | 24 ++++++++++++++++++++++++ mod/forum/version.php | 2 +- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/mod/forum/db/install.xml b/mod/forum/db/install.xml index 76dcc037896..bc446f10887 100644 --- a/mod/forum/db/install.xml +++ b/mod/forum/db/install.xml @@ -1,5 +1,5 @@ - @@ -150,7 +150,7 @@ - + @@ -167,4 +167,4 @@
-
+ \ No newline at end of file diff --git a/mod/forum/db/upgrade.php b/mod/forum/db/upgrade.php index 45f3e754ab5..9fbf31faea5 100644 --- a/mod/forum/db/upgrade.php +++ b/mod/forum/db/upgrade.php @@ -112,5 +112,29 @@ function xmldb_forum_upgrade($oldversion) { // Moodle v2.6.0 release upgrade line. // Put any upgrade step following this. + if ($oldversion < 2014040400) { + + // Define index userid-postid (not unique) to be dropped form forum_read. + $table = new xmldb_table('forum_read'); + $index = new xmldb_index('userid-postid', XMLDB_INDEX_NOTUNIQUE, array('userid', 'postid')); + + // Conditionally launch drop index userid-postid. + if ($dbman->index_exists($table, $index)) { + $dbman->drop_index($table, $index); + } + + + // Define index postid-userid (not unique) to be added to forum_read. + $index = new xmldb_index('postid-userid', XMLDB_INDEX_NOTUNIQUE, array('postid', 'userid')); + + // Conditionally launch add index postid-userid. + if (!$dbman->index_exists($table, $index)) { + $dbman->add_index($table, $index); + } + + // Forum savepoint reached. + upgrade_mod_savepoint(true, 2014040400, 'forum'); + } + return true; } diff --git a/mod/forum/version.php b/mod/forum/version.php index 3561dd99c55..1c33e0ef09a 100644 --- a/mod/forum/version.php +++ b/mod/forum/version.php @@ -24,7 +24,7 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2014021700; // The current module version (Date: YYYYMMDDXX) +$plugin->version = 2014040400; // The current module version (Date: YYYYMMDDXX) $plugin->requires = 2013110500; // Requires this Moodle version $plugin->component = 'mod_forum'; // Full name of the plugin (used for diagnostics) $plugin->cron = 60;