Commit 5b707dfe authored by Alex Vandiver's avatar Alex Vandiver
Browse files

Cache Attributes on the CurrentUser object, not an ephemeral User object

The previous commit moved preferences to using the Attributes cache;
however, this gains little because the cache is on the User object
derived from the CurrentUser, which is derived afresh each time that
RT->Config->Get() is called.

Call the ->Preferences method directly on the CurrentUser, instead of
the desrived User, so the cache is on the more durable CurrentUser
object.  The cache is cleared (via ->ClearAttributes) during the ->Load
call at the start of every request.  ->DeletePreferences is also
switched to use ->DeleteAttribute, which explicitly purges the cache;
otherwise, it may return stale data.

This better attribute caching ensures that even negative preferences
loads are cached for the duration of the request.  This, in turn,
eliminates a large number of repeated database queries (such as for the
username format preference) for users with no explicit preferences set.
parent a273c51b
......@@ -1013,7 +1013,6 @@ sub Get {
my $res;
if ( $user && $user->id && $META{$name}->{'Overridable'} ) {
$user = $user->UserObj if $user->isa('RT::CurrentUser');
my $prefs = $user->Preferences($RT::System);
$res = $prefs->{$name} if $prefs;
......@@ -1400,12 +1400,11 @@ sub DeletePreferences {
return (0, $self->loc("No permission to set preferences"))
unless $self->CurrentUserCanModify('Preferences');
my ($attr) = $self->Attributes->Named( $name );
if ( $attr ) {
return $attr->Delete;
my ($attr) = $self->DeleteAttribute( $name );
return (0, $self->loc("Preferences were not found"))
unless $attr;
return (0, $self->loc("Preferences were not found"));
return 1;
=head2 Stylesheet
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment