From 1db9b72e3577c556e47d28213e0bc73d57bae34a Mon Sep 17 00:00:00 2001 From: Daniel Neis Araujo Date: Tue, 15 Sep 2020 15:19:22 -0300 Subject: [PATCH] this adds basic indexes to avoid table scans --- db/install.xml | 143 +++++++++++++++++++++++++------------------------ db/upgrade.php | 23 ++++++++ version.php | 2 +- 3 files changed, 98 insertions(+), 70 deletions(-) diff --git a/db/install.xml b/db/install.xml index bc6aa29..08b018a 100644 --- a/db/install.xml +++ b/db/install.xml @@ -1,70 +1,75 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - -
-
-
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+
+
\ No newline at end of file diff --git a/db/upgrade.php b/db/upgrade.php index e0f3860..ed86ade 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -435,5 +435,28 @@ function xmldb_simplecertificate_upgrade($oldversion = 0) { // Simplecertificate savepoint reached. upgrade_mod_savepoint(true, 2017013001, 'simplecertificate'); } + if ($oldversion < 2020091500) { + + // Define index course (not unique) to be added to simplecertificate. + $table = new xmldb_table('simplecertificate'); + $index = new xmldb_index('course', XMLDB_INDEX_NOTUNIQUE, ['course']); + + // Conditionally launch add index course. + if (!$dbman->index_exists($table, $index)) { + $dbman->add_index($table, $index); + } + + // Define index certificate_user (not unique) to be added to simplecertificate_issues. + $table = new xmldb_table('simplecertificate_issues'); + $index = new xmldb_index('certificate_user', XMLDB_INDEX_NOTUNIQUE, ['certificateid', 'userid']); + + // Conditionally launch add index certificate_user. + if (!$dbman->index_exists($table, $index)) { + $dbman->add_index($table, $index); + } + + // Simplecertificate savepoint reached. + upgrade_mod_savepoint(true, 2020091500, 'simplecertificate'); + } return true; } diff --git a/version.php b/version.php index 79bfb51..aeabbc3 100644 --- a/version.php +++ b/version.php @@ -26,7 +26,7 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2020041239; // The current module version (Date: YYYYMMDDXX). +$plugin->version = 2020091500; // The current module version (Date: YYYYMMDDXX). $plugin->requires = 2020040800; // Requires this Moodle version (moodle 3.9.x). $plugin->cron = 4 * 3600; // Period for cron to check this module (secs). $plugin->component = 'mod_simplecertificate';