[Rt-commit] rt branch, 4.4/show-search-navigation-config, created. rt-4.4.4-125-g2b416e4950

? sunnavy sunnavy at bestpractical.com
Fri Aug 28 19:20:31 EDT 2020


The branch, 4.4/show-search-navigation-config has been created
        at  2b416e4950e5b72116edfb802227e22abe3c4290 (commit)

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

    Add config $ShowSearchNavigation to control if to build search navigation links
    
    Depending on search result count and config $TicketsItemMapSize,
    generating these links could slow down ticket display pages a lot.
    
    Reducing $TicketsItemMapSize could improve the performance, but at the
    price of completeness and accuracy.
    
    Using the new config could clearly avoid building these links.

diff --git a/etc/RT_Config.pm.in b/etc/RT_Config.pm.in
index 44e8ce56d1..b69cb10a4e 100644
--- a/etc/RT_Config.pm.in
+++ b/etc/RT_Config.pm.in
@@ -1334,7 +1334,7 @@ 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
@@ -1346,9 +1346,12 @@ 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.
 
+Set C<$ShowSearchNavigation> to 0 to not build these links.
+
 =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 2b416e4950e5b72116edfb802227e22abe3c4290
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;

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


More information about the rt-commit mailing list