Commit a273c51b authored by Alex Vandiver's avatar Alex Vandiver
Browse files

Use cached attribute list when fetching preferences

Attributes have, since their initial implementation, use
LoadByNameAndObject.  However, when the user does not have any
preferences stored, this can be very expensive, as
DBIx::SearchBuilder::Record::Cachable does not cache negative results --
that is, that the matching Attribute row does not exist.  This means
that every request for RT->Config->Get( '...', $session{CurrentUser})
results in an identical database query.

Use the ->Attributes method, which caches the set of user attributes.
This, in itself, is not sufficient to cause the preferences to be
cached; the the next commit.
parent ab424465
......@@ -1346,10 +1346,8 @@ sub Preferences {
my $name = _PrefName (shift);
my $default = shift;
my $attr = RT::Attribute->new( $self->CurrentUser );
$attr->LoadByNameAndObject( Object => $self, Name => $name );
my $content = $attr->Id ? $attr->Content : undef;
my ($attr) = $self->Attributes->Named( $name );
my $content = $attr ? $attr->Content : undef;
unless ( ref $content eq 'HASH' ) {
return defined $content ? $content : $default;
}
......@@ -1378,9 +1376,8 @@ sub SetPreferences {
return (0, $self->loc("No permission to set preferences"))
unless $self->CurrentUserCanModify('Preferences');
my $attr = RT::Attribute->new( $self->CurrentUser );
$attr->LoadByNameAndObject( Object => $self, Name => $name );
if ( $attr->Id ) {
my ($attr) = $self->Attributes->Named( $name );
if ( $attr ) {
my ($ok, $msg) = $attr->SetContent( $value );
return (1, "No updates made")
if $msg eq "That is already the current value";
......@@ -1403,9 +1400,8 @@ sub DeletePreferences {
return (0, $self->loc("No permission to set preferences"))
unless $self->CurrentUserCanModify('Preferences');
my $attr = RT::Attribute->new( $self->CurrentUser );
$attr->LoadByNameAndObject( Object => $self, Name => $name );
if ( $attr->Id ) {
my ($attr) = $self->Attributes->Named( $name );
if ( $attr ) {
return $attr->Delete;
}
......
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