Skip to content

Commit

Permalink
fix danmarsden#770 add indexes on attendance_log for update 2022090900
Browse files Browse the repository at this point in the history
  • Loading branch information
gbarat87 committed Oct 9, 2024
1 parent aedbe9c commit 1060f41
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions db/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
<INDEX NAME="sessionid" UNIQUE="false" FIELDS="sessionid"/>
<INDEX NAME="studentid" UNIQUE="false" FIELDS="studentid"/>
<INDEX NAME="statusid" UNIQUE="false" FIELDS="statusid"/>
<INDEX NAME="sessionid_studentid_statusid" UNIQUE="false" FIELDS="sessionid, studentid, statusid"/>
</INDEXES>
</TABLE>
<TABLE NAME="attendance_statuses" COMMENT="attendance_statuses table retrofitted from MySQL">
Expand Down
22 changes: 22 additions & 0 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,13 @@ function xmldb_attendance_upgrade($oldversion=0) {
upgrade_mod_savepoint(true, 2022083100, 'attendance');
}
if ($oldversion < 2022090900) {
$table = new xmldb_table('attendance_log');
$index = new xmldb_index('sessionid_studentid_statusid', XMLDB_KEY_UNIQUE, ['sessionid', 'studentid', 'statusid']);
// Conditionally launch add index sessionid_studentid_statusid.
if (!$dbman->index_exists($table, $index)) {
$dbman->add_index($table, $index);
}

if (!empty($CFG->dbfamily) && $CFG->dbfamily == 'postgres') {
$sql = 'DELETE FROM {attendance_log} a
WHERE a.id NOT IN (
Expand Down Expand Up @@ -814,5 +821,20 @@ function xmldb_attendance_upgrade($oldversion=0) {
upgrade_mod_savepoint(true, 2023020106, 'attendance');
}

if ($oldversion < 2023020109) {

// Add index on attendance_log for performance increase with update 2022090900.
$table = new xmldb_table('attendance_log');
$index = new xmldb_index('sessionid_studentid_statusid', XMLDB_KEY_UNIQUE, ['sessionid', 'studentid', 'statusid']);

// Conditionally launch add index sessionid_studentid_statusid.
if (!$dbman->index_exists($table, $index)) {
$dbman->add_index($table, $index);
}

// Attendance savepoint reached.
upgrade_mod_savepoint(true, 2023020109, 'attendance');
}

return true;
}
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
*/
defined('MOODLE_INTERNAL') || die();

$plugin->version = 2023020108;
$plugin->release = 2023020108;
$plugin->version = 2023020109;
$plugin->release = 2023020109;
$plugin->requires = 2022090200; // Requires 4.1.
$plugin->maturity = MATURITY_STABLE;
$plugin->cron = 0;
Expand Down

0 comments on commit 1060f41

Please sign in to comment.