[Rt-commit] [rtir] 01/01: Every time Queue::HasRight was checked, we loaded Queues from the DB
Kevin Falcone
falcone at bestpractical.com
Fri Feb 28 17:08:51 EST 2014
This is an automated email from the git hooks/post-receive script.
falcone pushed a commit to branch 3.0/cache-queues-hasright
in repository rtir.
commit 1f5fb2a9dbf1d4a41dbae415c34c386491a8ea40
Author: Kevin Falcone <falcone at bestpractical.com>
Date: Fri Feb 28 14:44:35 2014 -0500
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 - %';
---
lib/RT/IR.pm | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/lib/RT/IR.pm b/lib/RT/IR.pm
index da4bc20..dad138e 100644
--- a/lib/RT/IR.pm
+++ b/lib/RT/IR.pm
@@ -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;
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the rt-commit
mailing list