Skip to content

Commit 7caf6db

Browse files
committed
Make progressive generation of unpaginated search results configurable
Commit dda24a1 forced progressive (chunked) generation for unpaginated searches. This commit introduces $ProgressiveSearchResultRows (default 100) to control the chunk size, where 0 means to disable progressive generation and load the entire result set at once. It also drops the now-redundant $Collection->can('CombineSearchAndCount') guard in CollectionList: the required DBIx::SearchBuilder (>= 1.85) provides the method, and dashboard/saved-search collections are not special any more.
1 parent 54dee6c commit 7caf6db

7 files changed

Lines changed: 35 additions & 21 deletions

File tree

etc/RT_Config.pm.in

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3092,6 +3092,21 @@ Include "0" to provide the "Unlimited" option.
30923092

30933093
Set(@SearchResultsPerPage, qw(0 10 25 50 100));
30943094

3095+
=item C<$ProgressiveSearchResultRows>
3096+
3097+
For unpaginated searches (including TSV, iCal, and RSS exports), RT
3098+
progressively generates results by paging through the collection
3099+
C<$ProgressiveSearchResultRows> rows at a time. This does not change the
3100+
results, but can significantly reduce memory usage on large result sets.
3101+
The system default is 100.
3102+
3103+
Set this to 0 to disable progressive generation and load the entire
3104+
result set into memory at once.
3105+
3106+
=cut
3107+
3108+
Set( $ProgressiveSearchResultRows, 100 );
3109+
30953110
=item C<$UserTicketDataResultFormat>
30963111

30973112
This is the format of ticket search result for "Download User Tickets" links. It

lib/RT/Config.pm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2034,6 +2034,9 @@ our %META;
20342034
TicketsItemMapSize => {
20352035
Widget => '/Widgets/Form/Integer',
20362036
},
2037+
ProgressiveSearchResultRows => {
2038+
Widget => '/Widgets/Form/Integer',
2039+
},
20372040

20382041
AssetDefaultSearchResultOrderBy => {
20392042
Widget => '/Widgets/Form/String',

share/html/Elements/CollectionList

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,10 @@ $Collection->RowsPerPage( $Rows ) if $Rows;
7676
$Page = 1 unless $Page && $Page =~ /\A\d+\z/ && $Page > 1; # workaround problems with $Page = '' or undef
7777
$Collection->GotoPage( $Page - 1 ); # SB uses page 0 as the first page
7878

79-
# $Collection might not have CombineSearchAndCount method, like dashboards and saved searches.
80-
# Don't combine search and count for unpaginated searches, as we will progressively generate the result.
81-
$Collection->CombineSearchAndCount(1) if $Rows && $Collection->can('CombineSearchAndCount');
79+
# For unpaginated searches we progressively generate the result in chunks of
80+
# $ProgressiveSearchResultRows rows, and must not combine search and count then.
81+
my $ProgressiveRows = $Rows ? 0 : RT->Config->Get('ProgressiveSearchResultRows');
82+
$Collection->CombineSearchAndCount(1) unless $ProgressiveRows;
8283
$TotalFound = $Collection->CountAll() unless defined $TotalFound;
8384
return '' if !$TotalFound && !$ShowEmpty;
8485

@@ -159,11 +160,9 @@ if ( $ShowHeader ) {
159160

160161
my ($i, $column_map) = (0, {});
161162
$m->out('<tbody>');
162-
if ( !$Rows ) {
163-
$Collection->RowsPerPage(100);
164-
}
163+
$Collection->RowsPerPage($ProgressiveRows) if $ProgressiveRows;
165164

166-
while ( my $record = $Rows ? $Collection->Next : ( $Collection->Next || ( $Collection->NextPage && $Collection->Next ) ) ) {
165+
while ( my $record = $ProgressiveRows ? ( $Collection->Next || ( $Collection->NextPage && $Collection->Next ) ) : $Collection->Next ) {
167166
# Every ten rows, flush the buffer and put something on the page.
168167
$m->flush_buffer unless ++$i % 10;
169168

share/html/Elements/TSVExport

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ $Collection
5151
$Format
5252
$PreserveNewLines => 0
5353
$Filename => undef
54-
$RowsPerPage => 100
54+
$RowsPerPage => RT->Config->Get('ProgressiveSearchResultRows')
5555
</%ARGS>
5656
<%ONCE>
5757
my $no_html = HTML::Scrubber->new( deny => '*' );
@@ -137,10 +137,9 @@ for (@columns) {
137137
my $i = 0;
138138
my $ii = 0;
139139

140-
$RowsPerPage = 1000 if !$RowsPerPage || $RowsPerPage > 1000;
141-
$Collection->RowsPerPage($RowsPerPage);
140+
$Collection->RowsPerPage($RowsPerPage) if $RowsPerPage;
142141

143-
while ( my $row = ( $Collection->Next || ( $Collection->NextPage && $Collection->Next ) ) ) {
142+
while ( my $row = $RowsPerPage ? ( $Collection->Next || ( $Collection->NextPage && $Collection->Next ) ) : $Collection->Next ) {
144143
for my $col (@columns) {
145144
$m->out(join("\t", map {
146145
my $val = ProcessColumnMapValue($_->{map}, Arguments => [$row, $ii++], Escape => 0);

share/html/NoAuth/iCal/dhandler

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,9 @@ $feed->add_properties('calscale' => ['gregorian']);
9898
$feed->add_properties('method' => ['publish']);
9999
$feed->add_properties('prodid' => ["-//" . RT->Config->Get('rtname') ."//"]);
100100

101-
$RowsPerPage = 1000 if !$RowsPerPage || $RowsPerPage > 1000;
102-
$tickets->RowsPerPage($RowsPerPage);
101+
$tickets->RowsPerPage($RowsPerPage) if $RowsPerPage;
103102

104-
while ( my $t = ( $tickets->Next || ( $tickets->NextPage && $tickets->Next ) ) ) {
103+
while ( my $t = $RowsPerPage ? ( $tickets->Next || ( $tickets->NextPage && $tickets->Next ) ) : $tickets->Next ) {
105104
next unless $t->DueObj->IsSet;
106105

107106
my $starttime = $t->StartsObj->IsSet ? $t->StartsObj : $t->CreatedObj;
@@ -168,5 +167,5 @@ $m->abort;
168167
</%init>
169168

170169
<%args>
171-
$RowsPerPage => 100
170+
$RowsPerPage => RT->Config->Get('ProgressiveSearchResultRows')
172171
</%args>

share/html/Search/Elements/ResultsRSSView

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,8 @@ $rss->channel(
8888
},
8989
);
9090

91-
$RowsPerPage = 1000 if !$RowsPerPage || $RowsPerPage > 1000;
92-
$Tickets->RowsPerPage($RowsPerPage);
93-
while ( my $Ticket = ( $Tickets->Next || ( $Tickets->NextPage && $Tickets->Next ) ) ) {
91+
$Tickets->RowsPerPage($RowsPerPage) if $RowsPerPage;
92+
while ( my $Ticket = $RowsPerPage ? ( $Tickets->Next || ( $Tickets->NextPage && $Tickets->Next ) ) : $Tickets->Next ) {
9493
my $creator_str = $Ticket->CreatorObj->Format;
9594
$creator_str =~ s/[\r\n]//g;
9695

@@ -118,6 +117,6 @@ $m->abort();
118117
<%ARGS>
119118
$OrderBy => 'Created'
120119
$Order => 'ASC'
121-
$RowsPerPage => 100
120+
$RowsPerPage => RT->Config->Get('ProgressiveSearchResultRows')
122121
</%ARGS>
123122

share/html/Search/Results.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@
173173
}
174174
$session{$session_name}->RowsPerPage( $Rows ) if $Rows;
175175
$session{$session_name}->GotoPage( $Page - 1 );
176-
# Don't combine search and count for unpaginated searches, as we will progressively generate the result.
177-
$session{$session_name}->CombineSearchAndCount(1) if $Rows;
176+
# Don't combine search and count for unpaginated searches, as we progressively generate the result.
177+
$session{$session_name}->CombineSearchAndCount(1) if $Rows || !RT->Config->Get('ProgressiveSearchResultRows');
178178

179179
# Save the session again because we made changes
180180
# Otherwise the set below will restore it back to

0 commit comments

Comments
 (0)