Skip to content

Commit 63cfb19

Browse files
cbrandtbuffalosunnavy
authored andcommitted
In articles autocomplete, page until we get max results
We limit results rows to a page defined by max, but because of the per article rights check, some could be missed and we might return less than max. Keep going until we fill max or run out of records.
1 parent 2a9e2d6 commit 63cfb19

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

share/html/Helpers/Autocomplete/Articles

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,21 @@ $articles->Limit(
8989
SUBCLAUSE => 'excludeautocomplete'
9090
) if @not_in;
9191

92+
my $count = $articles->CountAll;
9293
my @suggestions;
93-
while (my $a = $articles->Next) {
94-
next if $right and not $a->CurrentUserHasRight($right);
95-
my $value = $a->$return;
96-
my $suggestion = { label => $a->Name, value => $value };
97-
$m->callback( CallbackName => "ModifySuggestion", suggestion => $suggestion, article => $a );
98-
push @suggestions, $suggestion;
94+
# RT::Articles->AddRecord filters by ShowArticle right, so some DB records
95+
# may be skipped. Keep paging until we collect max visible articles.
96+
OUTER: while (@suggestions < $max) {
97+
while (my $a = $articles->Next) {
98+
next if $right and not $a->CurrentUserHasRight($right);
99+
my $value = $a->$return;
100+
my $suggestion = { label => $a->Name, value => $value };
101+
$m->callback( CallbackName => "ModifySuggestion", suggestion => $suggestion, article => $a );
102+
push @suggestions, $suggestion;
103+
last OUTER if @suggestions >= $max;
104+
}
105+
$articles->NextPage;
106+
last if $articles->FirstRow >= $count;
99107
}
100108
return @suggestions if defined wantarray;
101109
</%INIT>

0 commit comments

Comments
 (0)