[Rt-devel] PATCH: optional limiting of content searches to inline content only

Kevin Murphy murphy at genome.chop.edu
Thu Dec 8 12:17:48 EST 2005


Here's a patch to 3.4.4 that adds a new RT config variable, 
$RT::InlineContentQueriesOnly:

# $InlineContentQueriesOnly: if this is set to a non-undef value,
# searches of ticket content (as in the Query Builder) will not search
# ticket attachments with filenames.  The default behavior is for
# content searches to search attached files in addition to in-line
# ticket content, which can be very slow for databases with many large
# attached files and is often not what users expect to happen, anyway.

The corresponding change to lib/RT/Tickets_Overlay.pm affects the 
_TransLimit sub.

-Kevin Murphy

-------------- next part --------------
diff -Naur rt-3.4.4/etc/RT_Config.pm rt-3.4.4-patch/etc/RT_Config.pm
--- rt-3.4.4/etc/RT_Config.pm	2005-12-08 11:39:59.000000000 -0500
+++ rt-3.4.4-patch/etc/RT_Config.pm	2005-12-08 11:42:04.000000000 -0500
@@ -135,6 +135,15 @@
 
 Set($DropLongAttachments , undef);
 
+# $InlineContentQueriesOnly: if this is set to a non-undef value,
+# searches of ticket content (as in the Query Builder) will not search
+# ticket attachments with filenames.  The default behavior is for
+# content searches to search attached files in addition to in-line
+# ticket content, which can be very slow for databases with many large
+# attached files and is often not what users expect to happen, anyway.
+
+Set($InlineContentQueriesOnly , undef);
+
 # If $ParseNewMessageForTicketCcs is true, RT will attempt to divine
 # Ticket 'Cc' watchers from the To and Cc lines of incoming messages
 # Be forewarned that if you have _any_ addresses which forward mail to
diff -Naur rt-3.4.4/lib/RT/Tickets_Overlay.pm rt-3.4.4-patch/lib/RT/Tickets_Overlay.pm
--- rt-3.4.4/lib/RT/Tickets_Overlay.pm	2005-12-08 11:40:25.000000000 -0500
+++ rt-3.4.4-patch/lib/RT/Tickets_Overlay.pm	2005-12-08 11:42:24.000000000 -0500
@@ -672,15 +672,40 @@
 
     $self->_OpenParen;
 
-    #Search for the right field
-    $self->_SQLLimit(
-        ALIAS         => $self->{_sql_trattachalias},
-        FIELD         => $field,
-        OPERATOR      => $op,
-        VALUE         => $value,
-        CASESENSITIVE => 0,
-        @rest
-    );
+    # Add the field-specific condition to the WHERE clause
+    if ($field ne 'Content' or !$RT::InlineContentQueriesOnly) {
+       # Normal case: simple field condition
+       $self->_SQLLimit(
+			ALIAS         => $self->{_sql_trattachalias},
+			FIELD         => $field,
+			OPERATOR      => $op,
+			VALUE         => $value,
+			CASESENSITIVE => 0,
+			@rest
+		       );
+    } else {
+       # Special case: content search where $RT::InlineContentQueriesOnly
+       # is defined: constrain the content search condition to only apply
+       # to attachments without filenames.
+       $self->_SQLLimit(
+			ALIAS         => $self->{_sql_trattachalias},
+			FIELD         => 'Filename',
+			OPERATOR      => 'IS',
+			VALUE         => 'NULL',
+			SUBCLAUSE     => 'contentquery',
+			ENTRYAGGREGATOR => 'AND',
+		       );
+       $self->_SQLLimit(
+			ALIAS         => $self->{_sql_trattachalias},
+			FIELD         => $field,
+			OPERATOR      => $op,
+			VALUE         => $value,
+			CASESENSITIVE => 0,
+			@rest,
+			ENTRYAGGREGATOR => 'AND',
+			SUBCLAUSE     => 'contentquery',
+		       );
+    }
 
     $self->_SQLJoin(
         ALIAS1 => $self->{_sql_trattachalias},


More information about the Rt-devel mailing list