From 6a3cffd3c6ac43b6ff395d23a522bfe21fc099db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mudr=C3=A1k?= Date: Mon, 18 Jun 2018 16:53:03 +0200 Subject: [PATCH] MDL-62621 comments: Add missing indexes on comments table The composite index over the fields contextid, commentarea and itemid helps the comments API to load all comments for the given area effectively. The index over the userid field helps the privacy API to load all comments by the given user. --- lib/db/install.xml | 6 +++++- lib/db/upgrade.php | 21 +++++++++++++++++++++ version.php | 2 +- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/lib/db/install.xml b/lib/db/install.xml index b9b900372d2..8e4dd6215f0 100644 --- a/lib/db/install.xml +++ b/lib/db/install.xml @@ -1,5 +1,5 @@ - @@ -2638,7 +2638,11 @@ + + + + diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index cc7edbd15a3..2f06ce21f6b 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -2233,5 +2233,26 @@ function xmldb_main_upgrade($oldversion) { // Automatically generated Moodle v3.5.0 release upgrade line. // Put any upgrade step following this. + if ($oldversion < 2018051700.07) { + // Add foreign key fk_user to the comments table. + $table = new xmldb_table('comments'); + $key = new xmldb_key('fk_user', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); + $dbman->add_key($table, $key); + + upgrade_main_savepoint(true, 2018051700.07); + } + + if ($oldversion < 2018051700.08) { + // Add composite index ix_concomitem to the table comments. + $table = new xmldb_table('comments'); + $index = new xmldb_index('ix_concomitem', XMLDB_INDEX_NOTUNIQUE, array('contextid', 'commentarea', 'itemid')); + + if (!$dbman->index_exists($table, $index)) { + $dbman->add_index($table, $index); + } + + upgrade_main_savepoint(true, 2018051700.08); + } + return true; } diff --git a/version.php b/version.php index af669ad210e..c21ecc30eae 100644 --- a/version.php +++ b/version.php @@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2018051700.06; // 20180517 = branching date YYYYMMDD - do not modify! +$version = 2018051700.08; // 20180517 = branching date YYYYMMDD - do not modify! // RR = release increments - 00 in DEV branches. // .XX = incremental changes.