[Rt-commit] rt branch, 4.4-trunk, updated. rt-4.4.4-453-g7a51a9e3d1

Jim Brandt jbrandt at bestpractical.com
Thu May 20 17:08:11 EDT 2021


The branch, 4.4-trunk has been updated
       via  7a51a9e3d131e41bc8d3b3185a3095aeee6fd72e (commit)
       via  764abd053bccb228adb608d0fcbb28adc19fcbcd (commit)
       via  ac4f68399b0251e642ec7d223c61ab65a07d277c (commit)
      from  8a6dcb2cffd5b979957570a86387f77faa4b44dd (commit)

Summary of changes:
 etc/RT_Config.pm.in            | 17 ++++++++++-----
 lib/RT/Config.pm               | 10 +++++++++
 share/html/Elements/Tabs       | 48 ++++++++++++++++++++++--------------------
 share/html/Ticket/Display.html |  2 +-
 t/web/search_linkdisplay.t     | 44 ++++++++++++++++++++++++++++++++++++++
 5 files changed, 92 insertions(+), 29 deletions(-)

- Log -----------------------------------------------------------------
commit ac4f68399b0251e642ec7d223c61ab65a07d277c
Author: craig kaiser <craig at bestpractical.com>
Date:   Tue Jun 23 10:17:15 2020 -0400

    Add $ShowSearchNavigation option to skip building search navigation links
    
    Depending on search result count and the $TicketsItemMapSize configuration,
    generating the first, prev, next, last links can slow down ticket
    display if the original search was resource intensive.
    
    Reducing $TicketsItemMapSize can improve performance, but
    the search still needs to be performed.
    
    This new option allows admins or users to completely omit running
    the search again to build the links.

diff --git a/etc/RT_Config.pm.in b/etc/RT_Config.pm.in
index 44e8ce56d1..97209fcb08 100644
--- a/etc/RT_Config.pm.in
+++ b/etc/RT_Config.pm.in
@@ -1334,21 +1334,28 @@ generated SQL statements, at the cost of the aforementioned bugs.
 
 Set($UseSQLForACLChecks, 1);
 
-=item C<$TicketsItemMapSize>
+=item C<$TicketsItemMapSize>, C<$ShowSearchNavigation>
 
 On the display page of a ticket from search results, RT provides links
 to the first, next, previous and last ticket from the results.  In
-order to build these links, RT needs to fetch the full result set from
-the database, which can be resource-intensive.
+order to build these links, RT needs to re-run the original search
+and fetch the full result set from the database. If the original
+search was resource-intensive, this will then slow down diplay of the
+ticket page.
 
-Set C<$TicketsItemMapSize> to number of tickets you want RT to examine
+Set C<$TicketsItemMapSize> to the number of tickets you want RT to examine
 to build these links. If the full result set is larger than this
 number, RT will omit the "last" link in the menu.  Set this to zero to
-always examine all results.
+always examine all results. This can improve performance for searches
+with large result sets.
+
+Set C<$ShowSearchNavigation> to 0 to not build these links at all and
+completely avoid re-running the original search query.
 
 =cut
 
 Set($TicketsItemMapSize, 1000);
+Set($ShowSearchNavigation, 1);
 
 =item C<$SearchResultsRefreshInterval>
 
diff --git a/lib/RT/Config.pm b/lib/RT/Config.pm
index 431a12ca22..87f1a027fa 100644
--- a/lib/RT/Config.pm
+++ b/lib/RT/Config.pm
@@ -568,6 +568,16 @@ our %META;
             Description => 'Hide unset fields?' # loc
         }
     },
+    ShowSearchNavigation => {
+        Section     => 'Ticket display',
+        Overridable => 1,
+        SortOrder   => 12,
+        Widget      => '/Widgets/Form/Boolean',
+        WidgetArguments => {
+            Description => 'Show search navigation', # loc
+            Hints       => 'Show search navigation links of "First", "Last", "Prev" and "Next"', # loc
+        }
+    },
 
     # User overridable locale options
     DateTimeFormat => {
diff --git a/share/html/Elements/Tabs b/share/html/Elements/Tabs
index f6233c33fa..106e38fe08 100644
--- a/share/html/Elements/Tabs
+++ b/share/html/Elements/Tabs
@@ -861,31 +861,33 @@ my $build_main_nav = sub {
                     path  => "/Articles/Article/ExtractIntoClass.html?Ticket=".$obj->id,
                 ) if $session{CurrentUser}->HasRight( Right => 'ShowArticlesMenu', Object => RT->System );
 
-                if ( defined $session{"tickets"} ) {
-                    # we have to update session data if we get new ItemMap
-                    my $updatesession = 1 unless ( $session{"tickets"}->{'item_map'} );
+                if ( RT::Config->Get( 'ShowSearchNavigation', $session{'CurrentUser'} ) ) {
+                    if ( defined $session{"tickets"} ) {
+                        # we have to update session data if we get new ItemMap
+                        my $updatesession = 1 unless ( $session{"tickets"}->{'item_map'} );
 
-                    my $item_map = $session{"tickets"}->ItemMap;
+                        my $item_map = $session{"tickets"}->ItemMap;
 
-                    if ($updatesession) {
-                        $session{"tickets"}->PrepForSerialization();
-                    }
+                        if ($updatesession) {
+                            $session{"tickets"}->PrepForSerialization();
+                        }
 
-                    my $search = Menu()->child('search')->child('tickets');
-                    # Don't display prev links if we're on the first ticket
-                    if ( $item_map->{$id}->{prev} ) {
-                        $search->child( first =>
-                            title => '<< ' . loc('First'), class => "nav", path => "/Ticket/Display.html?id=" . $item_map->{first});
-                        $search->child( prev =>
-                            title => '< ' . loc('Prev'),   class => "nav", path => "/Ticket/Display.html?id=" . $item_map->{$id}->{prev});
-                    }
-                    # Don't display next links if we're on the last ticket
-                    if ( $item_map->{$id}->{next} ) {
-                        $search->child( next =>
-                            title => loc('Next') . ' >',  class => "nav", path => "/Ticket/Display.html?id=" . $item_map->{$id}->{next});
-                        if ( $item_map->{last} ) {
-                            $search->child( last =>
-                                title => loc('Last') . ' >>', class => "nav", path => "/Ticket/Display.html?id=" . $item_map->{last});
+                        my $search = Menu()->child('search')->child('tickets');
+                        # Don't display prev links if we're on the first ticket
+                        if ( $item_map->{$id}->{prev} ) {
+                            $search->child( first =>
+                                title => '<< ' . loc('First'), class => "nav", path => "/Ticket/Display.html?id=" . $item_map->{first});
+                            $search->child( prev =>
+                                title => '< ' . loc('Prev'),   class => "nav", path => "/Ticket/Display.html?id=" . $item_map->{$id}->{prev});
+                        }
+                        # Don't display next links if we're on the last ticket
+                        if ( $item_map->{$id}->{next} ) {
+                            $search->child( next =>
+                                title => loc('Next') . ' >',  class => "nav", path => "/Ticket/Display.html?id=" . $item_map->{$id}->{next});
+                            if ( $item_map->{last} ) {
+                                $search->child( last =>
+                                    title => loc('Last') . ' >>', class => "nav", path => "/Ticket/Display.html?id=" . $item_map->{last});
+                            }
                         }
                     }
                 }
diff --git a/share/html/Ticket/Display.html b/share/html/Ticket/Display.html
index 2681a38313..bf64200bf0 100644
--- a/share/html/Ticket/Display.html
+++ b/share/html/Ticket/Display.html
@@ -240,7 +240,7 @@ my $attachments = $TicketObj->Attachments;
 my $attachment_content = $TicketObj->TextAttachments;
 
 my %link_rel;
-if (defined $session{'tickets'} and ($ARGS{'Query'} or $session{'CurrentSearchHash'}->{'Query'})) {
+if (RT::Config->Get( 'ShowSearchNavigation', $session{'CurrentUser'} ) && defined $session{'tickets'} and ($ARGS{'Query'} or $session{'CurrentSearchHash'}->{'Query'})) {
     my $item_map = $session{'tickets'}->ItemMap;
     $link_rel{first} = "/Ticket/Display.html?id=" . $item_map->{first}                if $item_map->{$TicketObj->Id}{prev};
     $link_rel{prev}  = "/Ticket/Display.html?id=" . $item_map->{$TicketObj->Id}{prev} if $item_map->{$TicketObj->Id}{prev};

commit 764abd053bccb228adb608d0fcbb28adc19fcbcd
Author: craig kaiser <craig at bestpractical.com>
Date:   Tue Jun 23 11:11:36 2020 -0400

    Add tests for $ShowSearchNavigation config

diff --git a/t/web/search_linkdisplay.t b/t/web/search_linkdisplay.t
index 8d18f547ad..4a12b0871a 100644
--- a/t/web/search_linkdisplay.t
+++ b/t/web/search_linkdisplay.t
@@ -59,4 +59,48 @@ $ref = $m->find_link( url_regex => qr!/Article/Display.html! );
 ok( $ref, "found article link" );
 is( $ref->text, $article->URIObj->Resolver->AsString, $article->URIObj->Resolver->AsString . " is displayed" );
 
+
+# Get a search that returns multiple tickets
+$m->get_ok("/Search/Results.html?Format=id,RefersTo;Query=id>0");
+
+ok $m->goto_ticket( $ticket->Id ), 'opened diplay page of ticket # ' . $ticket->Id;
+my $t_link = $m->find_link( id => "search-tickets-next" )->url;
+is( $t_link, "/Ticket/Display.html?id=" . $ticket2->Id, 'link to the next ticket in current search found' );
+
+diag "Set ShowSearchNavigation to false and confirm we do not load navigation links.";
+{
+    RT::Test->stop_server;
+    RT->Config->Set( 'ShowSearchNavigation' => 0 );
+    ( $baseurl, $m ) = RT::Test->started_ok;
+
+    # Get a search that returns multiple tickets
+    $m->get_ok("/Search/Results.html?Format=id,RefersTo;Query=id>0");
+
+    ok $m->goto_ticket( $ticket->Id ), 'opened diplay page of ticket # ' . $ticket->Id;
+    $t_link = $m->find_link( id => "search-tickets-next" );
+    is( $t_link, undef, "Search navigation results are not rendered" );
+}
+
+diag "Override ShowSearchNavigation at user pref level.";
+{
+    ok( $m->login( 'root', 'password' ), 'logged in as root' );
+
+    my $root = RT::User->new( RT->SystemUser );
+    $root->Load('root');
+    ok( $root->Id, "Loaded root user" );
+
+    $root->SetPreferences( $RT::System => { %{ $root->Preferences($RT::System) || {} }, ShowSearchNavigation => 1 } );
+
+    is( RT::Config->Get( 'ShowSearchNavigation', $root ), 1, "User pref for ShowSearchNavigation successfully set." );
+
+    $m->get_ok("/Search/Results.html?Format=id,RefersTo;Query=id>0");
+
+    ok $m->goto_ticket( $ticket->Id ), 'opened diplay page of ticket # ' . $ticket->Id;
+    my $t_link = $m->find_link( id => "search-tickets-next" )->url;
+    is( $t_link, "/Ticket/Display.html?id=" . $ticket2->Id, 'link to the next ticket in current search found' );
+
+    $root->SetPreferences( $RT::System => { %{ $root->Preferences($RT::System) || {} }, ShowSearchNavigation => 0 } );
+    is( RT::Config->Get( 'ShowSearchNavigation', $root ), 0, "User pref for ShowSearchNavigation successfully set." );
+}
+
 done_testing;

commit 7a51a9e3d131e41bc8d3b3185a3095aeee6fd72e
Merge: 8a6dcb2cff 764abd053b
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Thu May 20 16:55:26 2021 -0400

    Merge branch '4.4/show-search-navigation-config' into 4.4-trunk

diff --cc share/html/Elements/Tabs
index a6415e194f,106e38fe08..dd177feae7
--- a/share/html/Elements/Tabs
+++ b/share/html/Elements/Tabs
@@@ -871,32 -861,33 +871,34 @@@ my $build_main_nav = sub 
                      path  => "/Articles/Article/ExtractIntoClass.html?Ticket=".$obj->id,
                  ) if $session{CurrentUser}->HasRight( Right => 'ShowArticlesMenu', Object => RT->System );
  
-                 if ( defined $session{"tickets"} ) {
-                     # we have to update session data if we get new ItemMap
-                     my $updatesession;
-                     $updatesession = 1 unless ( $session{"tickets"}->{'item_map'} );
+                 if ( RT::Config->Get( 'ShowSearchNavigation', $session{'CurrentUser'} ) ) {
+                     if ( defined $session{"tickets"} ) {
+                         # we have to update session data if we get new ItemMap
 -                        my $updatesession = 1 unless ( $session{"tickets"}->{'item_map'} );
++                        my $updatesession;
++                        $updatesession = 1 unless ( $session{"tickets"}->{'item_map'} );
  
-                     my $item_map = $session{"tickets"}->ItemMap;
+                         my $item_map = $session{"tickets"}->ItemMap;
  
-                     if ($updatesession) {
-                         $session{"tickets"}->PrepForSerialization();
-                     }
+                         if ($updatesession) {
+                             $session{"tickets"}->PrepForSerialization();
+                         }
  
-                     my $search = Menu()->child('search')->child('tickets');
-                     # Don't display prev links if we're on the first ticket
-                     if ( $item_map->{$id}->{prev} ) {
-                         $search->child( first =>
-                             title => '<< ' . loc('First'), class => "nav", path => "/Ticket/Display.html?id=" . $item_map->{first});
-                         $search->child( prev =>
-                             title => '< ' . loc('Prev'),   class => "nav", path => "/Ticket/Display.html?id=" . $item_map->{$id}->{prev});
-                     }
-                     # Don't display next links if we're on the last ticket
-                     if ( $item_map->{$id}->{next} ) {
-                         $search->child( next =>
-                             title => loc('Next') . ' >',  class => "nav", path => "/Ticket/Display.html?id=" . $item_map->{$id}->{next});
-                         if ( $item_map->{last} ) {
-                             $search->child( last =>
-                                 title => loc('Last') . ' >>', class => "nav", path => "/Ticket/Display.html?id=" . $item_map->{last});
+                         my $search = Menu()->child('search')->child('tickets');
+                         # Don't display prev links if we're on the first ticket
+                         if ( $item_map->{$id}->{prev} ) {
+                             $search->child( first =>
+                                 title => '<< ' . loc('First'), class => "nav", path => "/Ticket/Display.html?id=" . $item_map->{first});
+                             $search->child( prev =>
+                                 title => '< ' . loc('Prev'),   class => "nav", path => "/Ticket/Display.html?id=" . $item_map->{$id}->{prev});
+                         }
+                         # Don't display next links if we're on the last ticket
+                         if ( $item_map->{$id}->{next} ) {
+                             $search->child( next =>
+                                 title => loc('Next') . ' >',  class => "nav", path => "/Ticket/Display.html?id=" . $item_map->{$id}->{next});
+                             if ( $item_map->{last} ) {
+                                 $search->child( last =>
+                                     title => loc('Last') . ' >>', class => "nav", path => "/Ticket/Display.html?id=" . $item_map->{last});
+                             }
                          }
                      }
                  }

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


More information about the rt-commit mailing list