[Rt-commit] rt branch, 5.0-trunk, updated. rt-5.0.1-14-g2add01dc31

? sunnavy sunnavy at bestpractical.com
Fri Feb 26 13:47:48 EST 2021


The branch, 5.0-trunk has been updated
       via  2add01dc31c26bab429997bfcab5934dd0849984 (commit)
      from  b994cf5217ba79dda16d4ff8e6c1ea3ded79a8d4 (commit)

Summary of changes:
 lib/RT/Tickets.pm      | 79 +++++++++++++++++++++++++-------------------------
 lib/RT/Transactions.pm | 78 ++++++++++++++++++++++++-------------------------
 2 files changed, 79 insertions(+), 78 deletions(-)

- Log -----------------------------------------------------------------
commit 2add01dc31c26bab429997bfcab5934dd0849984
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Sat Feb 27 01:46:06 2021 +0800

    Move priority translation before status for better performance
    
    Current priority translation needs to get queues mentioned in query, as
    GetReferencedQueues is not smart enough right now(it simply gets all the
    queues matching any Queue/Lifecycle item in query), when there are
    multiple lifecycles, queries contains "Status = '__Active__'" will be
    translated to something like:
    
        ( Lifecyle = "default" AND ( Status = "new" OR Status = "open" OR Status = "stalled" ) )
        OR
        ( Lifecyle = "foo" AND ( Status = "new" OR Status = "open" ) )
    
    The following GetReferencedQueues will then get all the queues, which
    could slow down searches a lot when there are thousands of queues.

diff --git a/lib/RT/Tickets.pm b/lib/RT/Tickets.pm
index 7886107d32..3a8afe8913 100644
--- a/lib/RT/Tickets.pm
+++ b/lib/RT/Tickets.pm
@@ -3035,6 +3035,46 @@ sub _parser {
     );
     die join "; ", map { ref $_ eq 'ARRAY' ? $_->[ 0 ] : $_ } @results if @results;
 
+    if ( RT->Config->Get('EnablePriorityAsString') ) {
+        my $queues = $tree->GetReferencedQueues( CurrentUser => $self->CurrentUser );
+        my %config = RT->Config->Get('PriorityAsString');
+        my @names;
+        if (%$queues) {
+            for my $id ( keys %$queues ) {
+                my $queue = RT::Queue->new( $self->CurrentUser );
+                $queue->Load($id);
+                if ( $queue->Id ) {
+                    push @names, $queue->__Value('Name');    # Skip ACL check
+                }
+            }
+        }
+        else {
+            @names = keys %config;
+        }
+
+        my %map;
+        for my $name (@names) {
+            if ( my $value = exists $config{$name} ? $config{$name} : $config{Default} ) {
+                my %hash = ref $value eq 'ARRAY' ? @$value : %$value;
+                for my $label ( keys %hash ) {
+                    $map{lc $label} //= $hash{$label};
+                }
+            }
+        }
+
+        $tree->traverse(
+            sub {
+                my $node = shift;
+                return unless $node->isLeaf;
+                my $value = $node->getNodeValue;
+                if ( $value->{Key} =~ /^(?:Initial|Final)?Priority$/i ) {
+                    $value->{Value} = $map{ lc $value->{Value} } if defined $map{ lc $value->{Value} };
+                }
+            }
+        );
+    }
+
+
     my ( $active_status_node, $inactive_status_node );
 
     my $escape_quotes = sub {
@@ -3133,45 +3173,6 @@ sub _parser {
         }
     );
 
-    if ( RT->Config->Get('EnablePriorityAsString') ) {
-        my $queues = $tree->GetReferencedQueues( CurrentUser => $self->CurrentUser );
-        my %config = RT->Config->Get('PriorityAsString');
-        my @names;
-        if (%$queues) {
-            for my $id ( keys %$queues ) {
-                my $queue = RT::Queue->new( $self->CurrentUser );
-                $queue->Load($id);
-                if ( $queue->Id ) {
-                    push @names, $queue->__Value('Name');    # Skip ACL check
-                }
-            }
-        }
-        else {
-            @names = keys %config;
-        }
-
-        my %map;
-        for my $name (@names) {
-            if ( my $value = exists $config{$name} ? $config{$name} : $config{Default} ) {
-                my %hash = ref $value eq 'ARRAY' ? @$value : %$value;
-                for my $label ( keys %hash ) {
-                    $map{lc $label} //= $hash{$label};
-                }
-            }
-        }
-
-        $tree->traverse(
-            sub {
-                my $node = shift;
-                return unless $node->isLeaf;
-                my $value = $node->getNodeValue;
-                if ( $value->{Key} =~ /^(?:Initial|Final)?Priority$/i ) {
-                    $value->{Value} = $map{ lc $value->{Value} } if defined $map{ lc $value->{Value} };
-                }
-            }
-        );
-    }
-
     # Perform an optimization pass looking for watcher bundling
     $tree->traverse(
         sub {
diff --git a/lib/RT/Transactions.pm b/lib/RT/Transactions.pm
index 9e4a8c5405..1107831efe 100644
--- a/lib/RT/Transactions.pm
+++ b/lib/RT/Transactions.pm
@@ -896,6 +896,45 @@ sub _parser {
     );
     die join "; ", map { ref $_ eq 'ARRAY' ? $_->[ 0 ] : $_ } @results if @results;
 
+    if ( RT->Config->Get('EnablePriorityAsString') ) {
+        my $queues = $tree->GetReferencedQueues( CurrentUser => $self->CurrentUser );
+        my %config = RT->Config->Get('PriorityAsString');
+        my @names;
+        if (%$queues) {
+            for my $id ( keys %$queues ) {
+                my $queue = RT::Queue->new( $self->CurrentUser );
+                $queue->Load($id);
+                if ( $queue->Id ) {
+                    push @names, $queue->__Value('Name');    # Skip ACL check
+                }
+            }
+        }
+        else {
+            @names = keys %config;
+        }
+
+        my %map;
+        for my $name (@names) {
+            if ( my $value = exists $config{$name} ? $config{$name} : $config{Default} ) {
+                my %hash = ref $value eq 'ARRAY' ? @$value : %$value;
+                for my $label ( keys %hash ) {
+                    $map{lc $label} //= $hash{$label};
+                }
+            }
+        }
+
+        $tree->traverse(
+            sub {
+                my $node = shift;
+                return unless $node->isLeaf;
+                my $value = $node->getNodeValue;
+                if ( $value->{Key} =~ /^Ticket(?:Initial|Final)?Priority$/i ) {
+                    $value->{Value} = $map{ lc $value->{Value} } if defined $map{ lc $value->{Value} };
+                }
+            }
+        );
+    }
+
 
     # To handle __Active__ and __InActive__ statuses, copied from
     # RT::Tickets::_parser with field name updates, i.e.
@@ -1001,45 +1040,6 @@ sub _parser {
         }
     );
 
-    if ( RT->Config->Get('EnablePriorityAsString') ) {
-        my $queues = $tree->GetReferencedQueues( CurrentUser => $self->CurrentUser );
-        my %config = RT->Config->Get('PriorityAsString');
-        my @names;
-        if (%$queues) {
-            for my $id ( keys %$queues ) {
-                my $queue = RT::Queue->new( $self->CurrentUser );
-                $queue->Load($id);
-                if ( $queue->Id ) {
-                    push @names, $queue->__Value('Name');    # Skip ACL check
-                }
-            }
-        }
-        else {
-            @names = keys %config;
-        }
-
-        my %map;
-        for my $name (@names) {
-            if ( my $value = exists $config{$name} ? $config{$name} : $config{Default} ) {
-                my %hash = ref $value eq 'ARRAY' ? @$value : %$value;
-                for my $label ( keys %hash ) {
-                    $map{lc $label} //= $hash{$label};
-                }
-            }
-        }
-
-        $tree->traverse(
-            sub {
-                my $node = shift;
-                return unless $node->isLeaf;
-                my $value = $node->getNodeValue;
-                if ( $value->{Key} =~ /^Ticket(?:Initial|Final)?Priority$/i ) {
-                    $value->{Value} = $map{ lc $value->{Value} } if defined $map{ lc $value->{Value} };
-                }
-            }
-        );
-    }
-
     my $ea = '';
     $tree->traverse(
         sub {

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


More information about the rt-commit mailing list