From 6edd064414e23a5edb81ec15dada9259fda9946e Mon Sep 17 00:00:00 2001 From: Mikhail Golenkov Date: Mon, 5 Oct 2020 12:11:28 +1100 Subject: [PATCH] MDL-69848 upgrade: Delete notifications in chunks --- message/output/popup/db/upgrade.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/message/output/popup/db/upgrade.php b/message/output/popup/db/upgrade.php index 9152c48eb2f..69daf6f3ad1 100644 --- a/message/output/popup/db/upgrade.php +++ b/message/output/popup/db/upgrade.php @@ -46,7 +46,22 @@ function xmldb_message_popup_upgrade($oldversion) { if ($oldversion < 2020020600) { // Clean up orphaned popup notification records. - $DB->delete_records_select('message_popup_notifications', 'notificationid NOT IN (SELECT id FROM {notifications})'); + $fromsql = "FROM {message_popup_notifications} mpn + LEFT JOIN {notifications} n + ON mpn.notificationid = n.id + WHERE n.id IS NULL"; + $total = $DB->count_records_sql("SELECT COUNT(mpn.id) " . $fromsql); + $i = 0; + $pbar = new progress_bar('deletepopupnotification', 500, true); + do { + if ($popupnotifications = $DB->get_records_sql("SELECT mpn.id " . $fromsql, null, 0, 1000)) { + list($insql, $inparams) = $DB->get_in_or_equal(array_keys($popupnotifications)); + $DB->delete_records_select('message_popup_notifications', "id $insql", $inparams); + // Update progress. + $i += count($inparams); + $pbar->update($i, $total, "Cleaning up orphaned popup notification records - $i/$total."); + } + } while ($popupnotifications); // Reportbuilder savepoint reached. upgrade_plugin_savepoint(true, 2020020600, 'message', 'popup'); -- 2.43.0