]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
www: don't memoize ->user_help contents
authorEric Wong <e@80x24.org>
Sat, 10 Aug 2024 09:00:07 +0000 (09:00 +0000)
committerEric Wong <e@80x24.org>
Sat, 17 Aug 2024 17:36:17 +0000 (17:36 +0000)
Generating it is cheap enough and not worth the extra memory
and long-lived allocations.  We can avoid allocating a
Xapian::QueryParser object here, too, to avoid wasting memory
for xap_helper external process users.

lib/PublicInbox/Search.pm
t/www_altid.t

index dfe0271b9a72822279fb1eed45d77a7edfe11462..784e3b0a4daad14f925a9f8c462b542bb17963a2 100644 (file)
@@ -598,16 +598,10 @@ sub qparse_new {
                $qp->add_boolean_prefix($name, $_) foreach split(/ /, $prefix);
        }
 
-       if (my $extra = $self->{-extra}) {
-               my $user_pfx = $self->{-user_pfx} = [];
-               for my $x (@$extra) {
-                       push @$user_pfx, $x->user_help;
-                       my $m = $x->query_parser_method;
-                       $qp->$m(@$x{qw(prefix xprefix)});
-               }
-               chomp @$user_pfx;
+       for my $x (@{$self->{-extra} // []}) {
+               my $m = $x->query_parser_method;
+               $qp->$m(@$x{qw(prefix xprefix)});
        }
-
        while (my ($name, $prefix) = each %prob_prefix) {
                $qp->add_prefix($name, $_) foreach split(/ /, $prefix);
        }
@@ -666,9 +660,7 @@ sub help2txt (@) { # also used by Documentation/common.perl
 }
 
 sub help_txt {
-       my ($self) = @_;
-       $self->{qp} // $self->qparse_new; # parse altids + indexheaders
-       help2txt(@HELP, @{$self->{-user_pfx} // []});
+       help2txt(@HELP, map { $_->user_help } @{$_[0]->{-extra} // []});
 }
 
 # always returns a scalar value
index 7ad4a1d2418823d5e9045f5202509ef0d0dddaaf..6f0f0c61ade6c82235f4bc864e1f86095a3611b2 100644 (file)
@@ -62,6 +62,9 @@ my $client = sub {
        is $res->code, 200, 'altid search hit';
        $res = $cb->(GET('/test/?q=xyz:10'));
        is $res->code, 404, 'altid search miss';
+       $res = $cb->(GET('/test/_/text/help/'));
+       is $res->code, 200, 'altid help hit';
+       like $res->content, qr/\b$aid:/, 'altid shown in help';
 };
 test_psgi(sub { $www->call(@_) }, $client);
 SKIP: {