From 1060f4167dfdf426888c3d6d38ea403c2a009d19 Mon Sep 17 00:00:00 2001 From: guillaumebarat Date: Wed, 9 Oct 2024 13:56:42 +1000 Subject: [PATCH] fix #770 add indexes on attendance_log for update 2022090900 --- db/install.xml | 1 + db/upgrade.php | 22 ++++++++++++++++++++++ version.php | 4 ++-- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/db/install.xml b/db/install.xml index 72eee3a35f6..8cd3f61e13c 100755 --- a/db/install.xml +++ b/db/install.xml @@ -85,6 +85,7 @@ + diff --git a/db/upgrade.php b/db/upgrade.php index 31f7ec55dff..917fb3e7704 100755 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -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 ( @@ -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; } diff --git a/version.php b/version.php index 11bb680b988..dc31ff37611 100755 --- a/version.php +++ b/version.php @@ -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;