From: Eric Wong Date: Sat, 10 Aug 2024 09:00:07 +0000 (+0000) Subject: www: don't memoize ->user_help contents X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9768ab794f400677386f6ac2926a0825c9df78fc;p=thirdparty%2Fpublic-inbox.git www: don't memoize ->user_help contents 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. --- diff --git a/lib/PublicInbox/Search.pm b/lib/PublicInbox/Search.pm index dfe0271b9..784e3b0a4 100644 --- a/lib/PublicInbox/Search.pm +++ b/lib/PublicInbox/Search.pm @@ -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 diff --git a/t/www_altid.t b/t/www_altid.t index 7ad4a1d24..6f0f0c61a 100644 --- a/t/www_altid.t +++ b/t/www_altid.t @@ -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: {