MDL-69888 core: Cache user fully setup status

This commit is contained in:
Brendan Heywood
2022-08-18 10:29:44 +10:00
parent 896e126a66
commit f0d91ec708
+13 -1
View File
@@ -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;
}
@@ -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;