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.
This commit is contained in:
Neill Magill 2020-06-25 09:11:50 +01:00
parent c11e2517a7
commit b6c7a25d60
3 changed files with 17 additions and 2 deletions

View file

@ -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;
}