Skip to content

Commit

Permalink
MDL-69888 core: Cache user fully setup status
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanheywood committed Aug 18, 2022
1 parent 896e126 commit f0d91ec
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lib/moodlelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -3445,9 +3445,18 @@ function update_user_login_times() {
* @return bool
*/
function user_not_fully_set_up($user, $strict = true) {
global $CFG;
global $CFG, $SESSION, $USER;
require_once($CFG->dirroot.'/user/profile/lib.php');

// If the user is setup then store this in the session to avoid re-checking.
// Some edge cases are when the users email starts to bounce or the
// configuration for custom fields has changed while they are logged in so
// we re-check this fully every hour for the rare cases it has changed.
if (isset($USER->id) && isset($user->id) && $USER->id === $user->id &&
isset($SESSION->fullysetupstrict) && (time() - $SESSION->fullysetupstrict) < HOURSECS) {
return false;
}

if (isguestuser($user)) {
return false;
}
Expand All @@ -3464,6 +3473,9 @@ function user_not_fully_set_up($user, $strict = true) {
if (!profile_has_required_custom_fields_set($user->id)) {
return true;
}
if (isset($USER->id) && isset($user->id) && $USER->id === $user->id) {
$SESSION->fullysetupstrict = time();
}
}

return false;
Expand Down

0 comments on commit f0d91ec

Please sign in to comment.