[Rt-commit] rt branch, 4.4/sql-convert-or-to-in, updated. rt-4.4.4-88-g2a0851982

? sunnavy sunnavy at bestpractical.com
Tue Feb 25 16:04:42 EST 2020


The branch, 4.4/sql-convert-or-to-in has been updated
       via  2a085198293b0c3f55768ee9cfd2ae10d6a86879 (commit)
      from  d16ab984de54033b445ff225ae0e65ea11b187f0 (commit)

Summary of changes:
 t/api/sql.t | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
 create mode 100644 t/api/sql.t

- Log -----------------------------------------------------------------
commit 2a085198293b0c3f55768ee9cfd2ae10d6a86879
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Wed Feb 26 04:57:42 2020 +0800

    Test SQL conversion of OR => IN
    
    It's mainly for ticket SQL, which involves tricky SQL tree manipulation.

diff --git a/t/api/sql.t b/t/api/sql.t
new file mode 100644
index 000000000..7241e6fb3
--- /dev/null
+++ b/t/api/sql.t
@@ -0,0 +1,37 @@
+use strict;
+use warnings;
+
+use RT::Test tests => undef;
+
+# The IN version of this SQL is 4x faster in a real RT instance.
+my $users = RT::Users->new( RT->SystemUser );
+$users->WhoHaveGroupRight( Right => 'OwnTicket', Object => RT->System, IncludeSuperusers => 1 );
+like(
+    $users->BuildSelectQuery,
+    qr{RightName IN \('SuperUser', 'OwnTicket'\)},
+    'RightName check in WhoHaveGroupRight uses IN'
+);
+
+my $root_id  = RT::Test->load_or_create_user( Name => 'root' )->id;
+my $alice_id = RT::Test->load_or_create_user( Name => 'alice' )->id;
+my $general_id = RT::Test->load_or_create_queue( Name => 'General' )->id;
+my $support_id = RT::Test->load_or_create_queue( Name => 'Support' )->id;
+
+my %ticketsql = (
+    q{Status = 'new' OR Status = 'open'}                => qr{Status IN \('new', 'open'\)},
+    q{Status = '__Active__'}                            => qr{Status IN \('new', 'open', 'stalled'\)},
+    q{id = 2 OR id = 3}                                 => qr{id IN \('2', '3'\)},
+    q{Creator = 'root' OR Creator = 'alice'}            => qr{Creator IN \('$alice_id', '$root_id'\)},
+    q{Queue = 'General' OR Queue = 'Support'}           => qr{Queue IN \('$general_id', '$support_id'\)},
+    q{Lifecycle = 'default' or Lifecycle = 'approvals'} => qr{Lifecycle IN \('approvals', 'default'\)},
+    q{(Queue = 'General' OR Queue = 'Support') AND (Status = 'new' OR Status = 'open')} =>
+        qr{Queue IN \('$general_id', '$support_id'\).+Status IN \('new', 'open'\)},
+);
+
+my $tickets = RT::Tickets->new( RT->SystemUser );
+for my $query ( sort keys %ticketsql ) {
+    $tickets->FromSQL($query);
+    like( $tickets->BuildSelectQuery, $ticketsql{$query}, qq{TicketSQL "$query" uses IN} );
+}
+
+done_testing;

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


More information about the rt-commit mailing list