From 4dcb3165e75e26ac3ccc46acf4ed3b331e34ca3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mudr=C3=A1k?= Date: Fri, 8 May 2020 14:14:07 +0200 Subject: [PATCH] MDL-68647 forum: Add index over posts privatereplyto field This is to further improve the performance of searching of posts related to the given user. Once both userid and privatereplyto are indexed, the query planner can use the merged index to search for posts records. --- mod/forum/db/install.xml | 3 ++- mod/forum/db/upgrade.php | 12 ++++++++++++ mod/forum/version.php | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/mod/forum/db/install.xml b/mod/forum/db/install.xml index ef7545dce73..bbda97aba99 100644 --- a/mod/forum/db/install.xml +++ b/mod/forum/db/install.xml @@ -1,5 +1,5 @@ - @@ -99,6 +99,7 @@ + diff --git a/mod/forum/db/upgrade.php b/mod/forum/db/upgrade.php index 7d36e0413b4..deb13e35e49 100644 --- a/mod/forum/db/upgrade.php +++ b/mod/forum/db/upgrade.php @@ -246,5 +246,17 @@ function xmldb_forum_upgrade($oldversion) { // Automatically generated Moodle v3.9.0 release upgrade line. // Put any upgrade step following this. + if ($oldversion < 2020061501) { + // Add index privatereplyto (not unique) to the forum_posts table. + $table = new xmldb_table('forum_posts'); + $index = new xmldb_index('privatereplyto', XMLDB_INDEX_NOTUNIQUE, ['privatereplyto']); + + if (!$dbman->index_exists($table, $index)) { + $dbman->add_index($table, $index); + } + + upgrade_mod_savepoint(true, 2020061501, 'forum'); + } + return true; } diff --git a/mod/forum/version.php b/mod/forum/version.php index 7eddcd86571..79355568051 100644 --- a/mod/forum/version.php +++ b/mod/forum/version.php @@ -24,6 +24,6 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2020061500; // The current module version (Date: YYYYMMDDXX) +$plugin->version = 2020061501; // The current module version (Date: YYYYMMDDXX) $plugin->requires = 2020060900; // Requires this Moodle version $plugin->component = 'mod_forum'; // Full name of the plugin (used for diagnostics)