From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 9FD301FC5C for ; Sat, 10 Aug 2024 09:00:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1723280414; bh=sp8wCCeYL1O/ujMwXZWm7SKE/5WTOt7Po0wJ+5hg7sY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=2sxrN/LAg66FWFmE6FlDiTIU685WkpShjSWLqSdtWa6bw03tK32tPlw4/sPvYkeig GtGRLLxxNpxUcHvEZjOCvwkdiUwyIxlMplG842D9RkRFxOYhDd6/xFG6ZMrfwuFHyq Kf7H0X9Nhhnn8xfhUdFJv4Qaoc/8YXXc3vBWwXls= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 06/11] www: don't memoize ->user_help contents Date: Sat, 10 Aug 2024 09:00:07 +0000 Message-ID: <20240810090012.23269-7-e@80x24.org> In-Reply-To: <20240810090012.23269-1-e@80x24.org> References: <20240810090012.23269-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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 | 16 ++++------------ t/www_altid.t | 3 +++ 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/lib/PublicInbox/Search.pm b/lib/PublicInbox/Search.pm index dfe0271b..784e3b0a 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 7ad4a1d2..6f0f0c61 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: {