MDL-64049 core: Cache prefs for current user

We were already caching these preferences when a user object is provided
to get_user_preferences, or when $USER is provided.

This changee swaps get_user_preferences to use the global USER object
when the USER->id matches the userid supplied to the function.
This commit is contained in:
Andrew Nicols 2018-11-16 13:58:54 +08:00
parent 01acb1ea90
commit 8cba8d1a58
2 changed files with 10 additions and 13 deletions

View file

@ -2088,7 +2088,11 @@ function get_user_preferences($name = null, $default = null, $user = null) {
} else if (isset($user->id)) {
// Is a valid object.
} else if (is_numeric($user)) {
$user = (object)array('id' => (int)$user);
if ($USER->id == $user) {
$user = $USER;
} else {
$user = (object)array('id' => (int)$user);
}
} else {
throw new coding_exception('Invalid $user parameter in get_user_preferences() call');
}