From: Eric Wong Date: Mon, 12 May 2025 20:44:58 +0000 (+0000) Subject: www: extmsg: rely on event loop for partial matches X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=058d38158499bf9e7f9d0f3e88063e8f36884429;p=thirdparty%2Fpublic-inbox.git www: extmsg: rely on event loop for partial matches Preparation for (optionally) using xap_helper to asynchronously look up Message-ID matches. This change does not materially change behavior, but will make subsequent changes easier to digest. --- diff --git a/lib/PublicInbox/ExtMsg.pm b/lib/PublicInbox/ExtMsg.pm index 251e430e8..c486467c3 100644 --- a/lib/PublicInbox/ExtMsg.pm +++ b/lib/PublicInbox/ExtMsg.pm @@ -104,6 +104,13 @@ sub ext_msg_step { } } +sub try_partial ($) { + my ($ctx) = @_; + bless $ctx, __PACKAGE__; # for ExtMsg->event_step + return $ctx->event_step if $ctx->{env}->{'pi-httpd.app'}; + $ctx->event_step(1) while $ctx->{-wcb}; +} + sub ext_msg_ALL ($) { my ($ctx) = @_; my $ALL = $ctx->{www}->{pi_cfg}->ALL or return; @@ -125,12 +132,11 @@ sub ext_msg_ALL ($) { return exact($ctx) if $ctx->{found}; # fall back to partial MID matching - for my $ibxish ($ctx->{ibx}, $ALL) { - my $mids = search_partial($ibxish, $ctx->{mid}) or next; - push @{$ctx->{partial}}, [ $ibxish, $mids ]; - last if ($ctx->{n_partial} += scalar(@$mids)) >= PARTIAL_MAX; + $ctx->{again} = [ $ctx->{ibx}, $ALL ]; + sub { + $ctx->{-wcb} = $_[0]; # HTTP server write callback + try_partial $ctx; } - partial_response($ctx); } # only public entry point @@ -170,7 +176,7 @@ sub event_step { sub finalize_exact { my ($ctx) = @_; - return $ctx->{-wcb}->(exact($ctx)) if $ctx->{found}; + return delete($ctx->{-wcb})->(exact($ctx)) if $ctx->{found}; # fall back to partial MID matching my $mid = $ctx->{mid}; @@ -180,14 +186,7 @@ sub finalize_exact { $ctx->{n_partial} = scalar(@$mids); push @{$ctx->{partial}}, [ $cur, $mids ]; } elsif ($ctx->{again} && length($mid) >= $MIN_PARTIAL_LEN) { - bless $ctx, __PACKAGE__; - if ($ctx->{env}->{'pi-httpd.app'}) { - $ctx->event_step; - return; - } - - # synchronous fall-through - $ctx->event_step while @{$ctx->{again}}; + return try_partial $ctx; } finalize_partial($ctx); } @@ -236,7 +235,7 @@ sub partial_response ($) { html_oneshot($ctx, $code); } -sub finalize_partial ($) { $_[0]->{-wcb}->(partial_response($_[0])) } +sub finalize_partial ($) { delete($_[0]->{-wcb})->(partial_response($_[0])) } sub ext_urls { my ($ctx, $mid, $href, $html) = @_;