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 057D41F44D for ; Fri, 12 Apr 2024 02:01:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1712887264; bh=TKzueRbWAhmuNVsXOMGJB1J21unO/mrwfD5JDleWNLc=; h=From:To:Subject:Date:From; b=NOydBFSvpB6frz0NDLPYve3xFcSKmK5+DPKhkfPxzUrlMRGXZrJNH6RhL4/YjX0Hg eLKPsE3w5eV/J66X072o/NoTUtJsEHxS5TDpnbtXYDtuU+sE1cyKUv0z4nlZWHGD9Y whZwyRbt4OCY2hYqZ3ZvYfmDJgYtMgkBw+0V1T9Y= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH] lei q: support --thread-id=$MSGID || -T $MSGID Date: Fri, 12 Apr 2024 02:01:03 +0000 Message-ID: <20240412020103.2665237-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: This adds support for the "POST /$INBOX/$MSGID/?x=m?q=..." added last year to support per-thread searches 764035c83 (www: support POST /$INBOX/$MSGID/?x=m&q=, 2023-03-30) This only supports instances of public-inbox since 764035c83, but unfortunately there hasn't been a release since then. --- Documentation/lei-q.pod | 9 +++++++++ lib/PublicInbox/LEI.pm | 1 + lib/PublicInbox/LeiXSearch.pm | 16 ++++++++++++---- t/psgi_v2.t | 16 ++++++++++++++++ 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/Documentation/lei-q.pod b/Documentation/lei-q.pod index 4476a806..79156750 100644 --- a/Documentation/lei-q.pod +++ b/Documentation/lei-q.pod @@ -129,6 +129,15 @@ lei/store unless an MUA unflags it! (Behavior undecided) Caveat: C<-tt> only works on locally-indexed messages at the moment, and not on remote (HTTP(S)) endpoints. +=item --thread-id=MSGID + +=item -T MSGID + +Only search messages in the same thread as the given Message-ID. + +For HTTP(S) externals, this only works on instances running +public-inbox 2.0+ (UNRELEASED). + =item --jobs=QUERY_WORKERS[,WRITE_WORKERS] =item --jobs=,WRITE_WORKERS diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm index 7c31ab43..06592358 100644 --- a/lib/PublicInbox/LEI.pm +++ b/lib/PublicInbox/LEI.pm @@ -177,6 +177,7 @@ our %CMD = ( # sorted in order of importance/use: 'stdin|', # /|\z/ must be first for lone dash @lxs_opt, @net_opt, qw(save! output|mfolder|o=s format|f=s dedupe|d=s threads|t+ + thread-id|T=s sort|s=s reverse|r offset=i pretty jobs|j=s globoff|g augment|a import-before! lock=s@ rsyncable alert=s@ mua=s verbose|v+ shared color! mail-sync!), @c_opt, opt_dash('limit|n=i', '[0-9]+') ], diff --git a/lib/PublicInbox/LeiXSearch.pm b/lib/PublicInbox/LeiXSearch.pm index fc95d401..d4f34733 100644 --- a/lib/PublicInbox/LeiXSearch.pm +++ b/lib/PublicInbox/LeiXSearch.pm @@ -13,7 +13,7 @@ use File::Temp 0.19 (); # 0.19 for ->newdir use File::Spec (); use PublicInbox::Search qw(xap_terms); use PublicInbox::Spawn qw(popen_rd popen_wr which); -use PublicInbox::MID qw(mids); +use PublicInbox::MID qw(mids mid_escape); use PublicInbox::Smsg; use PublicInbox::Eml; use PublicInbox::LEI; @@ -160,6 +160,8 @@ sub query_one_mset { # for --threads and l2m w/o sort my $can_kw = !!$ibxish->can('msg_keywords'); my $threads = $lei->{opt}->{threads} // 0; my $fl = $threads > 1 ? 1 : undef; + my $mid = $lei->{opt}->{'thread-id'}; + $mo->{threadid} = $over->mid2tid($mid) if defined $mid; my $lss = $lei->{lss}; my $maxk = "external.$dir.maxuid"; # max of previous, so our min my $min = $lss ? ($lss->{-cfg}->{$maxk} // 0) : 0; @@ -339,6 +341,12 @@ print STDERR $_; push @$curl, '-s', '-d', ''; my $each_smsg = $lei->{ovv}->ovv_each_smsg_cb($lei); $self->{import_sto} = $lei->{sto} if $lei->{opt}->{'import-remote'}; + if (defined(my $mid = $opt->{'thread-id'})) { + $mid = mid_escape($mid); + for my $uri (@$uris) { + $uri->path($uri->path.$mid.'/'); + } + } for my $uri (@$uris) { $lei->{-current_url} = $uri->as_string; my $start = time; @@ -459,7 +467,9 @@ sub concurrency { sub start_query ($$) { # always runs in main (lei-daemon) process my ($self, $lei) = @_; local $PublicInbox::LEI::current_lei = $lei; - if ($self->{opt_threads} || ($lei->{l2m} && !$self->{opt_sort})) { + if ($lei->{opt}->{threads} || + defined($lei->{opt}->{'thread-id'}) || + ($lei->{l2m} && !$lei->{opt}->{'sort'})) { for my $ibxish (locals($self)) { $self->wq_io_do('query_one_mset', [], $ibxish); } @@ -546,8 +556,6 @@ sub do_query { my $op_c = delete $lei->{pkt_op_c}; delete $lei->{pkt_op_p}; @$end = (); - $self->{opt_threads} = $lei->{opt}->{threads}; - $self->{opt_sort} = $lei->{opt}->{'sort'}; $self->{-do_lcat} = !!(delete $lei->{lcat_todo}); if ($l2m) { $l2m->net_merge_all_done($lei) unless $lei->{auth}; diff --git a/t/psgi_v2.t b/t/psgi_v2.t index 54faae9b..56a6ae8e 100644 --- a/t/psgi_v2.t +++ b/t/psgi_v2.t @@ -101,6 +101,19 @@ EOM } }; +my $test_lei_q_threadid = sub { + my ($u) = @_; + test_lei(sub { + lei_ok qw(q -f text --only), $u, qw(-T t@1 s:unrelated); + is $lei_out, '', 'no results on unlrelated thread'; + lei_ok qw(q -f text --only), $u, qw(-T t@1 dt:19931002000300..); + my @m = ($lei_out =~ m!^Message-ID: <([^>]+)>\n!gms); + is_deeply \@m, ['t@3'], 'got expected result from -T MSGID'; + }); +}; + +$test_lei_q_threadid->($m2t->{inboxdir}); + my $cfgpath = "$ibx->{inboxdir}/pi_config"; { open my $fh, '>', $cfgpath or BAIL_OUT $!; @@ -374,6 +387,9 @@ my $client3 = sub { $res = $cb->(POST("/m2t/t\@1/?q=s:unrelated&x=m")); is($res->code, 404, '404 on cross-thread search'); + + my $rmt = $ENV{PLACK_TEST_EXTERNALSERVER_URI}; + $rmt and $test_lei_q_threadid->("$rmt/m2t/"); }; test_psgi(sub { $www->call(@_) }, $client3); test_httpd($env, $client3, 4);