[Rt-commit] rt branch, 4.0/search-by-watcher-name-email, created. rt-4.0.8-350-ge613873

Ruslan Zakirov ruz at bestpractical.com
Fri Jan 11 15:23:42 EST 2013


The branch, 4.0/search-by-watcher-name-email has been created
        at  e613873845505b6b4f99b527c5489b31f069b29f (commit)

- Log -----------------------------------------------------------------
commit e613873845505b6b4f99b527c5489b31f069b29f
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Sat Jan 12 00:13:13 2013 +0400

    on search by watcher load user when possible
    
    Load user when we know that this will be one user record.
    This allows us put id into SQL instead of name/email address.
    
    EmailAddress is unique, but we don't have unique index and
    can not create one until we have solution for storing NULLs
    in DB.
    
    With the change mysql can better estimate number of records
    in CachedGroupMembers table and pick better plans.

diff --git a/lib/RT/Tickets.pm b/lib/RT/Tickets.pm
index 45f7e0c..a0fbd57 100644
--- a/lib/RT/Tickets.pm
+++ b/lib/RT/Tickets.pm
@@ -910,22 +910,23 @@ sub _WatcherLimit {
         die "Invalid watcher subfield: '$rest{SUBKEY}'";
     }
 
+    # 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 ( $op =~ /^!?=$/ && (!$rest{'SUBKEY'} || $rest{'SUBKEY'} eq 'Name' || $rest{'SUBKEY'} eq 'EmailAddress') ) {
+        my $o = RT::User->new( $self->CurrentUser );
+        my $method =
+            !$rest{'SUBKEY'}
+            ? $field eq 'Owner'? 'Load' : 'LoadByEmail'
+            : $rest{'SUBKEY'} eq 'EmailAddress' ? 'LoadByEmail': 'Load';
+        $o->$method( $value );
+        $rest{'SUBKEY'} = 'id';
+        $value = $o->id || 0;
+    }
+
     # Owner was ENUM field, so "Owner = 'xxx'" allowed user to
     # search by id and Name at the same time, this is workaround
     # to preserve backward compatibility
     if ( $field eq 'Owner' ) {
-        if ( $op =~ /^!?=$/ && (!$rest{'SUBKEY'} || $rest{'SUBKEY'} eq 'Name' || $rest{'SUBKEY'} eq 'EmailAddress') ) {
-            my $o = RT::User->new( $self->CurrentUser );
-            my $method = ($rest{'SUBKEY'}||'') eq 'EmailAddress' ? 'LoadByEmail': 'Load';
-            $o->$method( $value );
-            $self->_SQLLimit(
-                FIELD    => 'Owner',
-                OPERATOR => $op,
-                VALUE    => $o->id,
-                %rest,
-            );
-            return;
-        }
         if ( ($rest{'SUBKEY'}||'') eq 'id' ) {
             $self->_SQLLimit(
                 FIELD    => 'Owner',

-----------------------------------------------------------------------


More information about the Rt-commit mailing list