Commit 1f5fb2a9 authored by Kevin Falcone's avatar Kevin Falcone
Browse files

Every time Queue::HasRight was checked, we loaded Queues from the DB

Since a lot of RTIR code checks Queue::HasRight (particularly on CF right
checks) this was a ton of DB fetches to go get all the Constituency
Queues.  Just having the Constituency CF caused the queries, even if
there were no Queues to find.

This was especially apparent in the REST interface where merely listing
open Incident Reports caused thousands of SELECT main.* from Queues
where Name like 'Incidents - %';
parent 687540b2
......@@ -621,6 +621,7 @@ if ( RT::IR->HasConstituency ) {
wrap 'RT::Interface::Web::Handler::CleanupRequest', pre => sub {
%RT::IR::ConstituencyCache = ();
%RT::IR::HasNoQueueCache = ();
RT::IR::_FlushQueueHasRightCache();
};
require RT::Record;
......@@ -699,6 +700,7 @@ if ( RT::IR->HasConstituency ) {
return;
};
my $queue_cache = {};
wrap 'RT::Queue::HasRight', pre => sub {
return unless $_[0]->id;
return if $_[0]->{'disable_constituency_right_check'};
......@@ -710,16 +712,26 @@ if ( RT::IR->HasConstituency ) {
my %args = (@_[1..(@_-2)]);
$args{'Principal'} ||= $_[0]->CurrentUser;
my $queues = RT::Queues->new( RT->SystemUser );
$queues->Limit( FIELD => 'Name', OPERATOR => 'STARTSWITH', VALUE => "$name - " );
my $equiv_objects;
if ( $queue_cache->{$name} ) {
$equiv_objects = $queue_cache->{$name};
} else {
my $queues = RT::Queues->new( RT->SystemUser );
$queues->Limit( FIELD => 'Name', OPERATOR => 'STARTSWITH', VALUE => "$name - " );
$equiv_objects = $queues->ItemsArrayRef;
$queue_cache->{$name} = $equiv_objects;
}
my $has_right = $args{'Principal'}->HasRight(
%args,
Object => $_[0],
EquivObjects => $queues->ItemsArrayRef,
EquivObjects => $equiv_objects,
);
$_[-1] = $has_right;
return;
};
sub _FlushQueueHasRightCache { undef $queue_cache };
require RT::Queue;
......
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