Skip to content

Commit

Permalink
MDL-72025 Upgrade: Out of memory when updating social profile fields
Browse files Browse the repository at this point in the history
  • Loading branch information
sammarshallou committed Sep 2, 2021
1 parent 206023c commit 5d62223
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions user/profile/field/social/upgradelib.php
Expand Up @@ -145,8 +145,11 @@ function user_profile_social_create_profilefield($social) {
*/
function user_profile_social_update_module_availability() {
global $DB;
$modules = $DB->get_records('course_modules');
foreach ($modules as $mod) {
// Use transaction to improve performance if there are many individual database updates.
$transaction = $DB->start_delegated_transaction();
// Query all the course_modules entries that have availability set.
$rs = $DB->get_recordset_select('course_modules', 'availability IS NOT NULL', [], '', 'id, availability');
foreach ($rs as $mod) {
if (isset($mod->availability)) {
$availability = json_decode($mod->availability);
if (!is_null($availability)) {
Expand All @@ -159,6 +162,8 @@ function user_profile_social_update_module_availability() {
}
}
}
$rs->close();
$transaction->allow_commit();
}

/**
Expand All @@ -184,4 +189,4 @@ function user_profile_social_update_availability_structure(&$structure) {
}
}
}
}
}

0 comments on commit 5d62223

Please sign in to comment.