From 0ccf800f014e90fec3fe61c8d88bc0875a4f824a Mon Sep 17 00:00:00 2001 From: Jake Dallimore Date: Wed, 10 May 2023 09:41:38 +0800 Subject: [PATCH] MDL-76842 auth_lti: don't update the user unless data has changed When receiving data from the LTI launch, or service call, only update the user record when we know something has changed. This prevents the creation of many \core\event\user_updated events. --- auth/lti/auth.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/auth/lti/auth.php b/auth/lti/auth.php index dbca92ab8a2..9bf8975868e 100644 --- a/auth/lti/auth.php +++ b/auth/lti/auth.php @@ -380,7 +380,11 @@ class auth_plugin_lti extends \auth_plugin_base { 'lastname' => $userdata['family_name'] ?? $iss, 'email' => $email ]; - user_update_user($update); + $userfieldstocompare = array_intersect_key((array) $user, $update); + + if (!empty(array_diff($update, $userfieldstocompare))) { + user_update_user($update); // Only update if there's a change. + } if (!empty($userdata['picture'])) { try {