Skip to content

Commit f658b40

Browse files
authored
Merge pull request #197 from catalyst/add-indexes-MOODLE_35_STABLE
perf(db): add index to improve query times
2 parents a7e0b81 + b8a4a8e commit f658b40

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ jobs:
88
uses: catalyst/catalyst-moodle-workflows/.github/workflows/ci.yml@main
99
with:
1010
disable_behat: true
11+
disable_phpdoc: true

db/install.xml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
2-
<XMLDB PATH="admin/tool/trigger/db" VERSION="20210224" COMMENT="XMLDB file for Moodle admin/tool/trigger"
2+
<XMLDB PATH="admin/tool/trigger/db" VERSION="20221018" COMMENT="XMLDB file for Moodle admin/tool/trigger"
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xsi:noNamespaceSchemaLocation="../../../../lib/xmldb/xmldb.xsd"
55
>
@@ -161,6 +161,9 @@
161161
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
162162
<KEY NAME="eventid" TYPE="foreign" FIELDS="eventid" REFTABLE="tool_trigger_events" REFFIELDS="id" COMMENT="Relates to the event id in the events table."/>
163163
</KEYS>
164+
<INDEXES>
165+
<INDEX NAME="workflowid-number" UNIQUE="false" FIELDS="workflowid, number"/>
166+
</INDEXES>
164167
</TABLE>
165168
<TABLE NAME="tool_trigger_run_hist" COMMENT="Table to store run history">
166169
<FIELDS>
@@ -192,4 +195,4 @@
192195
</INDEXES>
193196
</TABLE>
194197
</TABLES>
195-
</XMLDB>
198+
</XMLDB>

db/upgrade.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,5 +350,20 @@ function xmldb_tool_trigger_upgrade($oldversion) {
350350
upgrade_plugin_savepoint(true, 2021030404, 'tool', 'trigger');
351351
}
352352

353+
if ($oldversion < 2021030408) {
354+
355+
// Define index workflowid-number (not unique) to be added to tool_trigger_workflow_hist.
356+
$table = new xmldb_table('tool_trigger_workflow_hist');
357+
$index = new xmldb_index('workflowid-number', XMLDB_INDEX_NOTUNIQUE, ['workflowid', 'number']);
358+
359+
// Conditionally launch add index workflowid-number.
360+
if (!$dbman->index_exists($table, $index)) {
361+
$dbman->add_index($table, $index);
362+
}
363+
364+
// Trigger savepoint reached.
365+
upgrade_plugin_savepoint(true, 2021030408, 'tool', 'trigger');
366+
}
367+
353368
return true;
354369
}

version.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
defined('MOODLE_INTERNAL') || die();
2626

2727
$plugin->component = 'tool_trigger';
28-
$plugin->release = 2021030407;
29-
$plugin->version = 2021030407;
28+
$plugin->release = 2021030408;
29+
$plugin->version = 2021030408;
3030
$plugin->requires = 2016052300;
3131
$plugin->supported = [35, 310];
3232
$plugin->maturity = MATURITY_STABLE;

0 commit comments

Comments
 (0)