- my $n_partial = 0;
- my @partial;
-
- eval { require PublicInbox::Msgmap };
- my $have_mm = $@ ? 0 : 1;
- if ($have_mm) {
- my $cgi = $ctx->{cgi};
- my $url = ref($cgi) eq 'CGI' ? $cgi->url(-base) . '/'
- : $cgi->base->as_string;
- $url .= $listname;
- unshift @pfx, { git_dir => $ctx->{git_dir}, url => $url };
- foreach my $pfx (@pfx) {
- my $git_dir = delete $pfx->{git_dir} or next;
- my $mm = eval { PublicInbox::Msgmap->new($git_dir) };
-
- $mm or next;
- if (my $res = $mm->mid_prefixes($mid)) {
- $n_partial += scalar(@$res);
- $pfx->{res} = $res;
- push @partial, $pfx;
- }
+ 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;
+ }
+ partial_response($ctx);
+}
+
+sub ext_msg {
+ my ($ctx) = @_;
+ ext_msg_ALL($ctx) // sub {
+ $ctx->{-wcb} = $_[0]; # HTTP server write callback
+
+ if ($ctx->{env}->{'pi-httpd.async'}) {
+ require PublicInbox::ConfigIter;
+ my $iter = PublicInbox::ConfigIter->new(
+ $ctx->{www}->{pi_cfg},
+ \&ext_msg_step, $ctx);
+ $iter->event_step;
+ } else {
+ $ctx->{www}->{pi_cfg}->each_inbox(\&ext_msg_i, $ctx);
+ finalize_exact($ctx);
+ }
+ };
+}
+
+# called via PublicInbox::DS::event_loop
+sub event_step {
+ my ($ctx, $sync) = @_;
+ # can't find a partial match in current inbox, try the others:
+ my $ibx = shift @{$ctx->{again}} or return finalize_partial($ctx);
+ my $mids = search_partial($ibx, $ctx->{mid}) or
+ return ($sync ? undef : PublicInbox::DS::requeue($ctx));
+ $ctx->{n_partial} += scalar(@$mids);
+ push @{$ctx->{partial}}, [ $ibx, $mids ];
+ $ctx->{n_partial} >= PARTIAL_MAX ? finalize_partial($ctx)
+ : ($sync ? undef : PublicInbox::DS::requeue($ctx));
+}
+
+sub finalize_exact {
+ my ($ctx) = @_;
+
+ return $ctx->{-wcb}->(exact($ctx)) if $ctx->{found};
+
+ # fall back to partial MID matching
+ my $mid = $ctx->{mid};
+ my $cur = $ctx->{ibx};
+ my $mids = search_partial($cur, $mid);
+ if ($mids) {
+ $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.async'}) {
+ $ctx->event_step;
+ return;