From b6c7a25d6050ea500aa63ffa00ecf72d07040bd4 Mon Sep 17 00:00:00 2001 From: Neill Magill Date: Thu, 25 Jun 2020 09:11:50 +0100 Subject: [PATCH] MDL-60583 webservice: Add index to improve token lookup performance Without this index every webservice call will do a full table scan when it tries to validate a token. On a busy site with many tokens this adds unnecessary load to the database. --- lib/db/install.xml | 5 ++++- lib/db/upgrade.php | 12 ++++++++++++ version.php | 2 +- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/db/install.xml b/lib/db/install.xml index 8f91417fa6b..0e0c4f0d49d 100644 --- a/lib/db/install.xml +++ b/lib/db/install.xml @@ -1,5 +1,5 @@ - @@ -2795,6 +2795,9 @@ + + + diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index dcc2f48034a..977d7dfa264 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -2486,5 +2486,17 @@ function xmldb_main_upgrade($oldversion) { upgrade_main_savepoint(true, 2020061500.02); } + if ($oldversion < 2020062600.01) { + // Add index to the token field in the external_tokens table. + $table = new xmldb_table('external_tokens'); + $index = new xmldb_index('token', XMLDB_INDEX_NOTUNIQUE, ['token']); + + if (!$dbman->index_exists($table, $index)) { + $dbman->add_index($table, $index); + } + + upgrade_main_savepoint(true, 2020062600.01); + } + return true; } diff --git a/version.php b/version.php index 104a1392a3a..b997323d8c7 100644 --- a/version.php +++ b/version.php @@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2020062600.00; // YYYYMMDD = weekly release date of this DEV branch. +$version = 2020062600.01; // YYYYMMDD = weekly release date of this DEV branch. // RR = release increments - 00 in DEV branches. // .XX = incremental changes. $release = '4.0dev (Build: 20200626)'; // Human-friendly version name