[Rt-commit] rt branch, 4.2/rolelimit-skip-user-join, created. rt-4.1.17-28-g8082d90
Alex Vandiver
alexmv at bestpractical.com
Wed Jul 17 17:05:23 EDT 2013
The branch, 4.2/rolelimit-skip-user-join has been created
at 8082d90f04e195d1af2e5fe0e77ca75bec690e4f (commit)
- Log -----------------------------------------------------------------
commit 8082d90f04e195d1af2e5fe0e77ca75bec690e4f
Author: Alex Vandiver <alexmv at bestpractical.com>
Date: Wed Jul 17 15:51:38 2013 -0400
Save a join to the Users table, when possible
It is unnecessary to join to CGM.MemberId to Users.id merely to limit on
Users.id; instead, limit directly on the MemberId. This theoretically
lets through rows where the MemberId points to a non-existant User, but
such cases are the result of database corruption already.
diff --git a/lib/RT/SearchBuilder/Role/Roles.pm b/lib/RT/SearchBuilder/Role/Roles.pm
index 63bbcb4..eeabbfc 100644
--- a/lib/RT/SearchBuilder/Role/Roles.pm
+++ b/lib/RT/SearchBuilder/Role/Roles.pm
@@ -364,21 +364,33 @@ sub RoleLimit {
$group_members ||= $self->_GroupMembersJoin(
GroupsAlias => $groups, New => 1, Left => 0
);
- $users ||= $self->Join(
- TYPE => 'LEFT',
- ALIAS1 => $group_members,
- FIELD1 => 'MemberId',
- TABLE2 => 'Users',
- FIELD2 => 'id',
- );
- $self->Limit(
- %args,
- ALIAS => $users,
- FIELD => $args{FIELD},
- OPERATOR => $args{OPERATOR},
- VALUE => $args{VALUE},
- CASESENSITIVE => 0,
- );
+ if ($args{FIELD} eq "id") {
+ # Save a left join to Users, if possible
+ $self->Limit(
+ %args,
+ ALIAS => $group_members,
+ FIELD => "MemberId",
+ OPERATOR => $args{OPERATOR},
+ VALUE => $args{VALUE},
+ CASESENSITIVE => 0,
+ );
+ } else {
+ $users ||= $self->Join(
+ TYPE => 'LEFT',
+ ALIAS1 => $group_members,
+ FIELD1 => 'MemberId',
+ TABLE2 => 'Users',
+ FIELD2 => 'id',
+ );
+ $self->Limit(
+ %args,
+ ALIAS => $users,
+ FIELD => $args{FIELD},
+ OPERATOR => $args{OPERATOR},
+ VALUE => $args{VALUE},
+ CASESENSITIVE => 0,
+ );
+ }
}
$self->_CloseParen( $args{SUBCLAUSE} ) if $args{SUBCLAUSE};
return ($groups, $group_members, $users);
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list