[Rt-commit] r6792 - in rtir/branches/2.1-EXPERIMENTAL: .

ruz at bestpractical.com ruz at bestpractical.com
Mon Jan 22 15:58:33 EST 2007


Author: ruz
Date: Mon Jan 22 15:58:33 2007
New Revision: 6792

Modified:
   rtir/branches/2.1-EXPERIMENTAL/   (props changed)
   rtir/branches/2.1-EXPERIMENTAL/lib/RT/Action/RTIR_SetConstituency.pm

Log:
 r1854 at cubic-pc:  cubic | 2007-01-23 00:09:40 +0300
 * split query into two by OR to improve mysql's plan


Modified: rtir/branches/2.1-EXPERIMENTAL/lib/RT/Action/RTIR_SetConstituency.pm
==============================================================================
--- rtir/branches/2.1-EXPERIMENTAL/lib/RT/Action/RTIR_SetConstituency.pm	(original)
+++ rtir/branches/2.1-EXPERIMENTAL/lib/RT/Action/RTIR_SetConstituency.pm	Mon Jan 22 15:58:33 2007
@@ -37,8 +37,7 @@
         ." OR Queue = 'Incident Reports'"
         ." OR Queue = 'Investigations'"
         ." OR Queue = 'Blocks'"
-        .")"
-        ." AND ( MemberOf = ". $ticket->Id ." OR HasMember = ". $ticket->Id ." )";
+        .")";
 
     if ( $constituency ) {
         $query .= " AND CF.{_RTIR_Constituency} != '$constituency'";
@@ -46,15 +45,18 @@
         $query .= " AND CF.{_RTIR_Constituency} IS NOT NULL";
     }
 
-    my $tickets = RT::Tickets->new( $RT::SystemUser );
-    $tickets->FromSQL( $query );
-    while ( my $t = $tickets->Next ) {
-        $RT::Logger->debug( "Ticket #". $t->id ." inherits constituency from ticket #". $ticket->id );
-        my ($res, $msg) = $t->AddCustomFieldValue(
-            Field => '_RTIR_Constituency',
-            Value => $constituency,
-        );
-        $RT::Logger->warning( "Couldn't set CF: $msg" ) unless $res;
+    # do two queries as mysql couldn't optimize things well
+    foreach my $link_type (qw(MemberOf HasMember)) {
+        my $tickets = RT::Tickets->new( $RT::SystemUser );
+        $tickets->FromSQL( $query ." AND $link_type = ". $ticket->Id );
+        while ( my $t = $tickets->Next ) {
+            $RT::Logger->debug( "Ticket #". $t->id ." inherits constituency from ticket #". $ticket->id );
+            my ($res, $msg) = $t->AddCustomFieldValue(
+                Field => '_RTIR_Constituency',
+                Value => $constituency,
+            );
+            $RT::Logger->warning( "Couldn't set CF: $msg" ) unless $res;
+        }
     }
     return 1;
 }


More information about the Rt-commit mailing list