Skip to content

Commit 94e6b5e

Browse files
committed
[#140] Add index for dialogueid for performance improvement
1 parent ee40096 commit 94e6b5e

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

db/install.xml

+1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
<INDEXES>
9292
<INDEX NAME="authorid" UNIQUE="false" FIELDS="authorid"/>
9393
<INDEX NAME="conversationid" UNIQUE="false" FIELDS="conversationid"/>
94+
<INDEX NAME="dialogueid" UNIQUE="false" FIELDS="dialogueid"/>
9495
</INDEXES>
9596
</TABLE>
9697
<TABLE NAME="dialogue_flags" COMMENT="Flags set against a dialogue, conversation or message e.g read">

db/upgrade.php

+18
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,23 @@
3030
* @return bool
3131
*/
3232
function xmldb_dialogue_upgrade($oldversion) {
33+
global $DB;
34+
35+
$dbman = $DB->get_manager();
36+
37+
if ($oldversion < 2024120900) {
38+
// Define index dialogueid (not unique) to be added to dialogue_messages.
39+
$table = new xmldb_table('dialogue_messages');
40+
$index = new xmldb_index('dialogueid', XMLDB_INDEX_NOTUNIQUE, ['dialogueid']);
41+
42+
// Conditionally launch add index userid.
43+
if (!$dbman->index_exists($table, $index)) {
44+
$dbman->add_index($table, $index);
45+
}
46+
47+
// savepoint reached.
48+
upgrade_mod_savepoint(true, 2024120900, 'dialogue');
49+
}
50+
3351
return true;
3452
}

version.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*/
2424
defined('MOODLE_INTERNAL') || die();
2525

26-
$plugin->version = 2024100901;
26+
$plugin->version = 2024120900;
2727
$plugin->release = 2024100901;
2828
$plugin->requires = 2022112805; // Requires 4.1 or higher.
2929
$plugin->component = 'mod_dialogue'; // Full name of the plugin (used for diagnostics).

0 commit comments

Comments
 (0)