1 # Copyright (C) 2020-2021 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 # Combine any combination of PublicInbox::Search,
5 # PublicInbox::ExtSearch, and PublicInbox::LeiSearch objects
7 package PublicInbox::LeiXSearch;
10 use parent qw(PublicInbox::LeiSearch PublicInbox::IPC);
11 use PublicInbox::DS qw(now);
12 use File::Temp 0.19 (); # 0.19 for ->newdir
14 use PublicInbox::Search qw(xap_terms);
15 use PublicInbox::Spawn qw(popen_rd spawn which);
16 use PublicInbox::MID qw(mids);
17 use PublicInbox::Smsg;
18 use PublicInbox::AutoReap;
21 use Fcntl qw(SEEK_SET F_SETFL O_APPEND O_RDWR);
22 use PublicInbox::ContentHash qw(git_sha);
23 use POSIX qw(strftime);
27 PublicInbox::Search::load_xapian();
29 qp_flags => $PublicInbox::Search::QP_FLAGS |
30 PublicInbox::Search::FLAG_PURE_NOT(),
35 my ($self, $ibxish) = @_; # ibxish = ExtSearch or Inbox
36 my $desc = $ibxish->{inboxdir} // $ibxish->{topdir};
37 my $srch = $ibxish->search //
38 return warn("$desc not indexed for Xapian ($@ $!)\n");
39 my @shards = $srch->xdb_shards_flat or
40 return warn("$desc has no Xapian shards\n");
42 if (delete $self->{xdb}) { # XXX: do we need this?
43 # clobber existing {xdb} if amending
44 my $expect = delete $self->{nshard};
45 my $shards = delete $self->{shards_flat};
46 scalar(@$shards) == $expect or die
47 "BUG: {nshard}$expect != shards=".scalar(@$shards);
50 for my $old_ibxish (@{$self->{shard2ibx}}) {
51 next if $prev == $old_ibxish;
53 my @shards = $old_ibxish->search->xdb_shards_flat;
54 push @{$self->{shards_flat}}, @shards;
56 my $nr = scalar(@{$self->{shards_flat}});
58 "BUG: reloaded $nr shards, expected $expect"
60 push @{$self->{shards_flat}}, @shards;
61 push(@{$self->{shard2ibx}}, $ibxish) for (@shards);
64 # returns a list of local inboxes (or count in scalar context)
65 sub locals { @{$_[0]->{locals} // []} }
67 sub remotes { @{$_[0]->{remotes} // []} }
69 # called by PublicInbox::Search::xdb (usually via ->mset)
70 sub xdb_shards_flat { @{$_[0]->{shards_flat} // []} }
72 sub _mitem_kw { # retry_reopen callback
73 my ($srch, $smsg, $mitem, $flagged) = @_;
74 my $doc = $mitem->get_document;
75 my $kw = xap_terms('K', $doc);
76 $kw->{flagged} = 1 if $flagged;
77 my @L = xap_terms('L', $doc);
78 # we keep the empty {kw} array here to prevent expensive work in
79 # ->xsmsg_vmd, _unbless_smsg will clobber it iff it's empty
80 $smsg->{kw} = [ sort keys %$kw ];
81 $smsg->{L} = \@L if scalar(@L);
84 sub mitem_kw ($$$;$) {
85 my ($srch, $smsg, $mitem, $flagged) = @_;
86 $srch->retry_reopen(\&_mitem_kw, $smsg, $mitem, $flagged);
91 my ($self, $mitem) = @_;
92 # cf. https://trac.xapian.org/wiki/FAQ/MultiDatabaseDocumentID
93 my $nshard = $self->{nshard};
94 my $docid = $mitem->get_docid;
95 my $shard = ($docid - 1) % $nshard;
96 my $num = int(($docid - 1) / $nshard) + 1;
97 my $ibx = $self->{shard2ibx}->[$shard];
98 my $smsg = $ibx->over->get_art($num);
99 return if $smsg->{bytes} == 0; # external message
100 if ($ibx->can('msg_keywords')) {
101 mitem_kw($self, $smsg, $mitem);
107 my ($self, $qstr, $opt) = @_;
109 $opt->{relevance} //= -2;
110 $self->mset($qstr //= 'z:1..', $opt);
115 sub _check_mset_limit ($$$) {
116 my ($lei, $desc, $mset) = @_;
117 return if defined($lei->{opt}->{limit}); # user requested limit
118 my $est = $mset->get_matches_estimated;
119 my $tot = $lei->{mset_opt}->{total};
120 $est > $tot and $lei->qerr(<<"");
121 # $desc estimated matches ($est) exceeds default --limit=$tot
125 sub _mset_more ($$) {
126 my ($mset, $mo) = @_;
127 my $size = $mset->size;
128 $size >= $mo->{limit} && (($mo->{offset} += $size) < $mo->{total});
131 # $startq will EOF when do_augment is done augmenting and allow
132 # query_combined_mset and query_thread_mset to proceed.
133 sub wait_startq ($) {
135 my $startq = delete $lei->{startq} or return;
137 my $n = sysread($startq, my $do_augment_done, 1);
139 return if $n == 0; # no MUA
140 if ($do_augment_done eq 'q') {
141 $lei->{opt}->{quiet} = 1;
142 delete $lei->{opt}->{verbose};
143 delete $lei->{-progress};
145 die "BUG: do_augment_done=`$do_augment_done'";
149 die "wait_startq: $!" unless $!{EINTR};
155 return if $lei->{early_mua} || !$lei->{-progress};
156 if ($lei->{pkt_op_p}) {
157 $lei->{pkt_op_p}->pkt_do('mset_progress', @_);
158 } else { # single lei-daemon consumer
159 my ($desc, $mset_size, $mset_total_est) = @_;
160 $lei->{-mset_total} += $mset_size if $mset_total_est ne '?';
161 $lei->qerr("# $desc $mset_size/$mset_total_est");
167 $lei->{-nr_write} += $nr;
170 sub query_one_mset { # for --threads and l2m w/o sort
171 my ($self, $ibxish) = @_;
172 local $0 = "$0 query_one_mset";
173 my $lei = $self->{lei};
174 my ($srch, $over) = ($ibxish->search, $ibxish->over);
175 my $dir = $ibxish->{inboxdir} // $ibxish->{topdir};
176 return warn("$dir not indexed by Xapian\n") unless ($srch && $over);
177 bless $srch, 'PublicInbox::LeiSearch'; # for ->qparse_new
178 my $mo = { %{$lei->{mset_opt}} }; # copy
180 my $each_smsg = $lei->{ovv}->ovv_each_smsg_cb($lei);
181 my $can_kw = !!$ibxish->can('msg_keywords');
182 my $threads = $lei->{opt}->{threads} // 0;
183 my $fl = $threads > 1 ? 1 : undef;
184 my $lss = $lei->{lss};
185 my $maxk = "external.$dir.maxuid";
186 my $stop_at = $lss ? $lss->{-cfg}->{$maxk} : undef;
187 if (defined $stop_at) {
189 return warn("$maxk=$stop_at has multiple values\n");
190 ($stop_at =~ /[^0-9]/) and
191 return warn("$maxk=$stop_at not numeric\n");
195 $mset = $srch->mset($mo->{qstr}, $mo);
196 mset_progress($lei, $dir, $mo->{offset} + $mset->size,
197 $mset->get_matches_estimated);
198 wait_startq($lei); # wait for keyword updates
199 my $ids = $srch->mset_to_artnums($mset, $mo);
200 @$ids = grep { $_ > $stop_at } @$ids if defined($stop_at);
203 # copy $ids if $lss since over->expand_thread
204 # shifts @{$ctx->{ids}}
205 $first_ids = [ @$ids ] if $lss;
206 my $ctx = { ids => $ids };
207 my %n2item = map { ($ids->[$i++], $_) } $mset->items;
208 while ($over->expand_thread($ctx)) {
209 for my $n (@{$ctx->{xids}}) {
210 my $smsg = $over->get_art($n) or next;
211 my $mitem = delete $n2item{$n};
212 next if $smsg->{bytes} == 0;
213 if ($mitem && $can_kw) {
214 mitem_kw($srch, $smsg, $mitem,
216 } elsif ($mitem && $fl) {
217 # call ->xsmsg_vmd, later
218 $smsg->{lei_q_tt_flagged} = 1;
220 $each_smsg->($smsg, $mitem);
222 @{$ctx->{xids}} = ();
226 my @items = $mset->items;
228 my $mitem = $items[$i++];
229 my $smsg = $over->get_art($n) or next;
230 next if $smsg->{bytes} == 0;
231 mitem_kw($srch, $smsg, $mitem, $fl) if $can_kw;
232 $each_smsg->($smsg, $mitem);
235 } while (_mset_more($mset, $mo));
236 _check_mset_limit($lei, $dir, $mset);
237 if ($lss && scalar(@$first_ids)) {
239 my $max = $first_ids->[0];
240 $lss->cfg_set($maxk, $max);
243 undef $each_smsg; # may commit
244 $lei->{ovv}->ovv_atexit_child($lei);
247 sub query_combined_mset { # non-parallel for non-"--threads" users
249 local $0 = "$0 query_combined_mset";
250 my $lei = $self->{lei};
251 my $mo = { %{$lei->{mset_opt}} };
253 for my $loc (locals($self)) {
254 attach_external($self, $loc);
256 my $each_smsg = $lei->{ovv}->ovv_each_smsg_cb($lei);
258 $mset = $self->mset($mo->{qstr}, $mo);
259 mset_progress($lei, 'xsearch', $mo->{offset} + $mset->size,
260 $mset->get_matches_estimated);
261 wait_startq($lei); # wait for keyword updates
262 for my $mitem ($mset->items) {
263 my $smsg = smsg_for($self, $mitem) or next;
264 $each_smsg->($smsg, $mitem);
266 } while (_mset_more($mset, $mo));
267 _check_mset_limit($lei, 'xsearch', $mset);
268 undef $each_smsg; # may commit
269 $lei->{ovv}->ovv_atexit_child($lei);
272 sub _smsg_fill ($$) {
273 my ($smsg, $eml) = @_;
274 $smsg->populate($eml);
275 $smsg->parse_references($eml, mids($eml));
276 $smsg->{$_} //= '' for qw(from to cc ds subject references mid);
277 delete @$smsg{qw(From Subject -ds -ts)};
280 sub each_remote_eml { # callback for MboxReader->mboxrd
281 my ($eml, $self, $lei, $each_smsg) = @_;
282 my $xoids = $lei->{ale}->xoids_for($eml, 1);
283 my $smsg = bless {}, 'PublicInbox::Smsg';
284 if ($self->{import_sto} && !$xoids) {
285 my ($res, $kw) = $self->{import_sto}->wq_do('add_eml', $eml);
286 $smsg = $res if ref($res) eq ref($smsg); # totally new message
287 $smsg->{kw} = $kw; # short-circuit xsmsg_vmd
289 $smsg->{blob} //= $xoids ? (keys(%$xoids))[0]
290 : $lei->git_oid($eml)->hexdigest;
291 _smsg_fill($smsg, $eml);
293 if ($lei->{-progress}) {
294 ++$lei->{-nr_remote_eml};
296 my $next = $lei->{-next_progress} //= ($now + 1);
298 $lei->{-next_progress} = $now + 1;
299 my $nr = $lei->{-nr_remote_eml};
300 mset_progress($lei, $lei->{-current_url}, $nr, '?');
303 $each_smsg->($smsg, undef, $eml);
306 sub fudge_qstr_time ($$$) {
307 my ($lei, $uri, $qstr) = @_;
308 return ($qstr, undef) unless $lei->{lss};
309 my $cfg = $lei->{lss}->{-cfg} // die 'BUG: no lss->{-cfg}';
310 my $cfg_key = "external.$uri.lastresult";
311 my $lr = $cfg->{$cfg_key} or return ($qstr, $cfg_key);
312 if ($lr !~ /\A\-?[0-9]+\z/) {
314 "$cfg->{-f}: $cfg_key=$lr not an integer, ignoring");
315 return ($qstr, $cfg_key);
317 my $rft = $lei->{opt}->{'remote-fudge-time'};
318 if ($rft && $rft !~ /\A-?[0-9]+\z/) {
319 my @t = $lei->{lss}->git->date_parse($rft);
320 my $diff = time - $t[0];
321 $lei->qerr("# $rft => $diff seconds");
324 $lr -= ($rft || (48 * 60 * 60));
325 $lei->qerr("# $uri limiting to ".
326 strftime('%Y-%m-%d %k:%M %z', localtime($lr)). ' and newer');
327 # this should really be rt: (received-time), but no stable
328 # public-inbox releases support it, yet.
329 my $dt = 'dt:'.strftime('%Y%m%d%H%M%S', gmtime($lr)).'..';
331 substr($qstr, 0, 0, '(');
334 ($qstr .= $dt, $cfg_key);
337 sub query_remote_mboxrd {
338 my ($self, $uris) = @_;
339 local $0 = "$0 query_remote_mboxrd";
340 local $SIG{TERM} = sub { exit(0) }; # for DESTROY (File::Temp, $reap)
341 my $lei = $self->{lei};
342 my $opt = $lei->{opt};
343 my $qstr = $lei->{mset_opt}->{qstr};
344 $qstr =~ s/[ \n\t]+/ /sg; # make URLs less ugly
345 my @qform = (x => 'm');
346 push(@qform, t => 1) if $opt->{threads};
347 my $verbose = $opt->{verbose};
349 my $cerr = File::Temp->new(TEMPLATE => 'curl.err-XXXX', TMPDIR => 1);
350 fcntl($cerr, F_SETFL, O_APPEND|O_RDWR) or warn "set O_APPEND: $!";
351 my $rdr = { 2 => $cerr };
353 # spawn a process to force line-buffering, otherwise curl
354 # will write 1 character at-a-time and parallel outputs
355 # mmmaaayyy llloookkk llliiikkkeee ttthhhiiisss
356 my $o = { 1 => $lei->{2}, 2 => $lei->{2} };
357 my $pid = spawn(['tail', '-f', $cerr->filename], undef, $o);
358 $reap_tail = PublicInbox::AutoReap->new($pid);
360 my $curl = PublicInbox::LeiCurl->new($lei, $self->{curl}) or return;
361 push @$curl, '-s', '-d', '';
362 my $each_smsg = $lei->{ovv}->ovv_each_smsg_cb($lei);
363 $self->{import_sto} = $lei->{sto} if $lei->{opt}->{'import-remote'};
364 for my $uri (@$uris) {
365 $lei->{-current_url} = $uri->as_string;
366 $lei->{-nr_remote_eml} = 0;
368 my ($q, $key) = fudge_qstr_time($lei, $uri, $qstr);
369 $uri->query_form(@qform, q => $q);
370 my $cmd = $curl->for_uri($lei, $uri);
371 $lei->qerr("# $cmd");
372 my ($fh, $pid) = popen_rd($cmd, undef, $rdr);
373 my $reap_curl = PublicInbox::AutoReap->new($pid);
374 $fh = IO::Uncompress::Gunzip->new($fh, MultiStream => 1);
375 PublicInbox::MboxReader->mboxrd($fh, \&each_remote_eml, $self,
377 my $nr = $lei->{-nr_remote_eml};
378 my $wait = $lei->{sto}->wq_do('done') if $nr && $lei->{sto};
381 # don't update if no results, maybe MTA is down
383 $lei->{lss}->cfg_set($key, $start);
384 mset_progress($lei, $lei->{-current_url}, $nr, $nr);
389 seek($cerr, 0, SEEK_SET) //
390 warn "seek($cmd stderr): $!";
391 $err = do { local $/; <$cerr> } //
392 warn "read($cmd stderr): $!";
393 truncate($cerr, 0) // warn "truncate($cmd stderr): $!";
396 next if (($? >> 8) == 22 && $err =~ /\b404\b/);
397 $uri->query_form(q => $qstr);
398 $lei->child_error($?, "E: <$uri> $err");
401 $lei->{ovv}->ovv_atexit_child($lei);
404 sub git { $_[0]->{git} // die 'BUG: git uninitialized' }
406 sub xsearch_done_wait { # dwaitpid callback
407 my ($arg, $pid) = @_;
408 my ($wq, $lei) = @$arg;
409 $lei->child_error($?, 'non-fatal error from '.ref($wq)) if $?;
412 sub query_done { # EOF callback for main daemon
414 local $PublicInbox::LEI::current_lei = $lei;
416 my $l2m = delete $lei->{l2m};
418 ($lei->{opt}->{'mail-sync'} && !$lei->{sto}) and
419 warn "BUG: {sto} missing with --mail-sync";
420 $lei->sto_done_request if $lei->{sto};
421 if (my $v2w = delete $lei->{v2w}) {
422 my $wait = $v2w->wq_do('done'); # may die
425 $lei->{ovv}->ovv_end($lei);
426 if ($l2m) { # close() calls LeiToMail reap_compress
427 if (my $out = delete $lei->{old_1}) {
428 if (my $mbout = $lei->{1}) {
429 close($mbout) or die <<"";
430 Error closing $lei->{ovv}->{dst}: \$!=$! \$?=$?
435 if ($l2m->lock_free) {
438 } else { # mbox users
439 delete $l2m->{mbl}; # drop dotlock
442 if ($lei->{-progress}) {
443 my $tot = $lei->{-mset_total} // 0;
444 my $nr = $lei->{-nr_write} // 0;
446 my $m = "# $nr written to " .
447 "$lei->{ovv}->{dst} ($tot matches)";
448 $nr ? $lei->qfin($m) : $lei->qerr($m);
450 $lei->qerr("# $tot matches");
453 $lei->start_mua if $l2m && !$l2m->lock_free;
456 $lei->fail($@) if $@;
459 sub do_post_augment {
461 local $PublicInbox::LEI::current_lei = $lei;
462 my $l2m = $lei->{l2m} or return; # client disconnected
465 $l2m->post_augment($lei);
469 if (my $lxs = delete $lei->{lxs}) {
470 $lxs->wq_kill('-TERM');
475 if (!$err && delete $lei->{early_mua}) { # non-augment case
476 eval { $lei->start_mua };
477 $lei->fail($@) if $@;
479 close(delete $lei->{au_done}); # triggers wait_startq in lei_xsearch
482 sub incr_post_augment { # called whenever an l2m shard finishes augment
484 my $l2m = $lei->{l2m} or return; # client disconnected
485 return if ++$lei->{nr_post_augment} != $l2m->{-wq_nr_workers};
486 do_post_augment($lei);
489 my $MAX_PER_HOST = 4;
492 my ($self, $opt) = @_;
493 my $nl = $opt->{threads} ? locals($self) : 1;
494 my $nr = remotes($self);
495 $nr = $MAX_PER_HOST if $nr > $MAX_PER_HOST;
499 sub start_query ($$) { # always runs in main (lei-daemon) process
500 my ($self, $lei) = @_;
501 local $PublicInbox::LEI::current_lei = $lei;
502 if ($self->{opt_threads} || ($lei->{l2m} && !$self->{opt_sort})) {
503 for my $ibxish (locals($self)) {
504 $self->wq_io_do('query_one_mset', [], $ibxish);
506 } elsif (locals($self)) {
507 $self->wq_io_do('query_combined_mset', []);
511 for my $uri (remotes($self)) {
512 push @{$q->[$i++ % $MAX_PER_HOST]}, $uri;
515 $self->wq_io_do('query_remote_mboxrd', [], $uris);
517 if ($self->{-do_lcat}) {
518 $self->wq_io_do('lcat_dump', []);
520 $self->wq_close; # lei_xsearch workers stop when done
523 sub incr_start_query { # called whenever an l2m shard starts do_post_auth
524 my ($self, $lei) = @_;
525 my $l2m = $lei->{l2m};
526 return if ++$self->{nr_start_query} != $l2m->{-wq_nr_workers};
527 start_query($self, $lei);
530 sub ipc_atfork_child {
532 $self->{lei}->_lei_atfork_child;
533 $self->SUPER::ipc_atfork_child;
537 my ($self, $lei) = @_;
538 my $l2m = $lei->{l2m};
540 'sigpipe_handler' => [ $lei ],
541 'fail_handler' => [ $lei ],
542 'do_post_augment' => [ \&do_post_augment, $lei ],
543 'incr_post_augment' => [ \&incr_post_augment, $lei ],
544 '' => [ \&query_done, $lei ],
545 'mset_progress' => [ \&mset_progress, $lei ],
546 'l2m_progress' => [ \&l2m_progress, $lei ],
548 'child_error' => [ $lei ],
549 'incr_start_query' => [ $self, $lei ],
551 $lei->{auth}->op_merge($ops, $l2m, $lei) if $l2m && $lei->{auth};
552 my $end = $lei->pkt_op_pair;
553 $lei->{1}->autoflush(1);
554 $lei->start_pager if delete $lei->{need_pager};
555 $lei->{ovv}->ovv_begin($lei);
556 die 'BUG: xdb|over open' if $lei->{lse}->{xdb} || $lei->{lse}->{over};
558 $l2m->pre_augment($lei);
559 if ($lei->{opt}->{augment} && delete $lei->{early_mua}) {
562 my $F_SETPIPE_SZ = $^O eq 'linux' ? 1031 : undef;
563 if ($l2m->{-wq_nr_workers} > 1 &&
564 $l2m->{base_type} =~ /\A(?:maildir|mbox)\z/) {
565 # setup two barriers to coordinate ->has_entries
566 # between l2m workers
567 pipe(my ($a_r, $a_w)) or die "pipe: $!";
568 fcntl($a_r, $F_SETPIPE_SZ, 4096) if $F_SETPIPE_SZ;
569 pipe(my ($b_r, $b_w)) or die "pipe: $!";
570 fcntl($b_r, $F_SETPIPE_SZ, 4096) if $F_SETPIPE_SZ;
571 $l2m->{au_peers} = [ $a_r, $a_w, $b_r, $b_w ];
573 $l2m->wq_workers_start('lei2mail', undef,
574 $lei->oldset, { lei => $lei });
575 $l2m->wq_wait_async(\&xsearch_done_wait, $lei);
576 pipe($lei->{startq}, $lei->{au_done}) or die "pipe: $!";
577 fcntl($lei->{startq}, $F_SETPIPE_SZ, 4096) if $F_SETPIPE_SZ;
578 delete $l2m->{au_peers};
580 $self->wq_workers_start('lei_xsearch', undef,
581 $lei->oldset, { lei => $lei });
582 $self->wq_wait_async(\&xsearch_done_wait, $lei);
583 my $op_c = delete $lei->{pkt_op_c};
584 delete $lei->{pkt_op_p};
586 $self->{opt_threads} = $lei->{opt}->{threads};
587 $self->{opt_sort} = $lei->{opt}->{'sort'};
588 $self->{-do_lcat} = !!(delete $lei->{lcat_todo});
590 $l2m->net_merge_all_done($lei) unless $lei->{auth};
592 start_query($self, $lei);
594 $lei->event_step_init; # wait for shutdowns
595 $lei->wait_wq_events($op_c, $ops);
599 my ($self, $uri) = @_;
600 if (my $curl = $self->{curl} //= which('curl') // 0) {
601 require PublicInbox::MboxReader;
602 require IO::Uncompress::Gunzip;
603 require PublicInbox::LeiCurl;
604 push @{$self->{remotes}}, $uri;
606 warn "curl missing, ignoring $uri\n";
610 sub prepare_external {
611 my ($self, $loc, $boost) = @_; # n.b. already ordered by boost
612 if (ref $loc) { # already a URI, or PublicInbox::Inbox-like object
613 return add_uri($self, $loc) if $loc->can('scheme');
614 } elsif ($loc =~ m!\Ahttps?://!) {
616 return add_uri($self, URI->new($loc));
617 } elsif (-f "$loc/ei.lock") {
618 require PublicInbox::ExtSearch;
619 die "`\\n' not allowed in `$loc'\n" if index($loc, "\n") >= 0;
620 $loc = PublicInbox::ExtSearch->new($loc);
621 } elsif (-f "$loc/inbox.lock" || -d "$loc/public-inbox") {
622 die "`\\n' not allowed in `$loc'\n" if index($loc, "\n") >= 0;
623 require PublicInbox::Inbox; # v2, v1
624 $loc = bless { inboxdir => $loc }, 'PublicInbox::Inbox';
626 warn "W: $loc gone, perhaps run: lei forget-external $loc\n";
629 warn "W: $loc ignored, unable to determine external type\n";
632 push @{$self->{locals}}, $loc;
635 sub _lcat_i { # LeiMailSync->each_src iterator callback
636 my ($oidbin, $id, $each_smsg) = @_;
637 $each_smsg->({blob => unpack('H*', $oidbin), pct => 100});
640 sub _lcat2smsg { # git->cat_async callback
641 my ($bref, $oid, $type, $size, $smsg) = @_;
643 my $eml = PublicInbox::Eml->new($bref);
644 my $json_dump = delete $smsg->{-json_dump};
645 bless $smsg, 'PublicInbox::Smsg';
646 _smsg_fill($smsg, $eml);
647 $json_dump->($smsg, undef, $eml);
651 sub lcat_dump { # via wq_io_do
653 my $lei = $self->{lei};
654 my $each_smsg = $lei->{ovv}->ovv_each_smsg_cb($lei);
655 my $git = $lei->{ale}->git;
657 my $json_dump = $each_smsg;
660 $smsg->{-json_dump} = $json_dump;
661 $git->cat_async($smsg->{blob}, \&_lcat2smsg, $smsg);
665 for my $ent (@{$lei->{lcat_todo}}) {
666 if (ref $ent eq 'HASH') { # { fid => $fid ,.. }
667 $lms //= $lei->{lse}->lms;
668 $lms->each_src($ent, \&_lcat_i, $each_smsg);
670 $each_smsg->({ blob => $ent, pct => 100 });
673 $git->async_wait_all;
674 undef $each_smsg; # may commit
675 $lei->{ovv}->ovv_atexit_child($lei);