[Rt-commit] rt branch, 4.2/search-by-watcher-name-email, created. rt-4.1.6-242-g3ecba1f
Alex Vandiver
alexmv at bestpractical.com
Tue Feb 12 18:31:27 EST 2013
The branch, 4.2/search-by-watcher-name-email has been created
at 3ecba1f8ad8992e1334efac827f065e85595751d (commit)
- Log -----------------------------------------------------------------
commit 3ecba1f8ad8992e1334efac827f065e85595751d
Author: Alex Vandiver <alexmv at bestpractical.com>
Date: Tue Feb 12 18:27:46 2013 -0500
When an explicit name or email and an = search, search by id internally
This commit re-implements e613873 on the refactored code that exists in
master. "Owner" searching by Name instead of EmailAddress is
generalized into "any stored-in-Column type" instead.
diff --git a/lib/RT/SearchBuilder/Role/Roles.pm b/lib/RT/SearchBuilder/Role/Roles.pm
index ea538e1..7e738c1 100644
--- a/lib/RT/SearchBuilder/Role/Roles.pm
+++ b/lib/RT/SearchBuilder/Role/Roles.pm
@@ -219,34 +219,35 @@ sub RoleLimit {
my $class = $args{CLASS} || $self->_RoleGroupClass;
$args{FIELD} ||= 'id' if $args{VALUE} =~ /^\d+$/;
+
my $type = delete $args{TYPE};
- if ($type) {
- unless ($class->HasRole($type)) {
- RT->Logger->warn("RoleLimit called with invalid role $type for $class");
- return;
- }
- my $column = $class->Role($type)->{Column};
- if ( $column ) {
- if ( $args{OPERATOR} =~ /^!?=$/
- && (!$args{FIELD} || $args{FIELD} eq 'Name' || $args{FIELD} eq 'EmailAddress') ) {
- my $o = RT::User->new( $self->CurrentUser );
- my $method = ($args{FIELD}||'') eq 'EmailAddress' ? 'LoadByEmail': 'Load';
- $o->$method( $args{VALUE} );
- $self->Limit(
- %args,
- FIELD => $column,
- VALUE => $o->id,
- );
- return;
- }
- if ( $args{FIELD} and $args{FIELD} eq 'id' ) {
- $self->Limit(
- %args,
- FIELD => $column,
- );
- return;
- }
- }
+ if ($type and not $class->HasRole($type)) {
+ RT->Logger->warn("RoleLimit called with invalid role $type for $class");
+ return;
+ }
+
+ my $column = $type ? $class->Role($type)->{Column} : undef;
+
+ # if it's equality op and search by Email or Name then we can preload user
+ # we do it to help some DBs better estimate number of rows and get better plans
+ if ( $args{OPERATOR} =~ /^!?=$/
+ && (!$args{FIELD} || $args{FIELD} eq 'Name' || $args{FIELD} eq 'EmailAddress') ) {
+ my $o = RT::User->new( $self->CurrentUser );
+ my $method =
+ !$args{FIELD}
+ ? ($column ? 'Load' : 'LoadByEmail')
+ : $args{FIELD} eq 'EmailAddress' ? 'LoadByEmail': 'Load';
+ $o->$method( $args{VALUE} );
+ $args{FIELD} = 'id';
+ $args{VALUE} = $o->id || 0;
+ }
+
+ if ( $column and $args{FIELD} and $args{FIELD} eq 'id' ) {
+ $self->Limit(
+ %args,
+ FIELD => $column,
+ );
+ return;
}
$args{FIELD} ||= 'EmailAddress';
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list