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 if (ref($res) eq ref($smsg)) { # totally new message
288 $self->{-imported} = 1;
290 $smsg->{kw} = $kw; # short-circuit xsmsg_vmd
292 $smsg->{blob} //= $xoids ? (keys(%$xoids))[0]
293 : $lei->git_oid($eml)->hexdigest;
294 _smsg_fill($smsg, $eml);
296 my $nr = ++$lei->{-nr_remote_eml}; # needed for lss->cfg_set
297 if ($lei->{-progress}) {
299 my $next = $lei->{-next_progress} //= ($now + 1);
301 $lei->{-next_progress} = $now + 1;
302 mset_progress($lei, $lei->{-current_url}, $nr, '?');
305 $each_smsg->($smsg, undef, $eml);
308 sub fudge_qstr_time ($$$) {
309 my ($lei, $uri, $qstr) = @_;
310 return ($qstr, undef) unless $lei->{lss};
311 my $cfg = $lei->{lss}->{-cfg} // die 'BUG: no lss->{-cfg}';
312 my $cfg_key = "external.$uri.lastresult";
313 my $lr = $cfg->{$cfg_key} or return ($qstr, $cfg_key);
314 if ($lr !~ /\A\-?[0-9]+\z/) {
316 "$cfg->{-f}: $cfg_key=$lr not an integer, ignoring");
317 return ($qstr, $cfg_key);
319 my $rft = $lei->{opt}->{'remote-fudge-time'};
320 if ($rft && $rft !~ /\A-?[0-9]+\z/) {
321 my @t = $lei->{lss}->git->date_parse($rft);
322 my $diff = time - $t[0];
323 $lei->qerr("# $rft => $diff seconds");
326 $lr -= ($rft || (48 * 60 * 60));
327 $lei->qerr("# $uri limiting to ".
328 strftime('%Y-%m-%d %k:%M %z', localtime($lr)). ' and newer');
329 # this should really be rt: (received-time), but no stable
330 # public-inbox releases support it, yet.
331 my $dt = 'dt:'.strftime('%Y%m%d%H%M%S', gmtime($lr)).'..';
333 substr($qstr, 0, 0, '(');
336 ($qstr .= $dt, $cfg_key);
339 sub query_remote_mboxrd {
340 my ($self, $uris) = @_;
341 local $0 = "$0 query_remote_mboxrd";
342 local $SIG{TERM} = sub { exit(0) }; # for DESTROY (File::Temp, $reap)
343 my $lei = $self->{lei};
344 my $opt = $lei->{opt};
345 my $qstr = $lei->{mset_opt}->{qstr};
346 $qstr =~ s/[ \n\t]+/ /sg; # make URLs less ugly
347 my @qform = (x => 'm');
348 push(@qform, t => 1) if $opt->{threads};
349 my $verbose = $opt->{verbose};
351 my $cerr = File::Temp->new(TEMPLATE => 'curl.err-XXXX', TMPDIR => 1);
352 fcntl($cerr, F_SETFL, O_APPEND|O_RDWR) or warn "set O_APPEND: $!";
353 my $rdr = { 2 => $cerr };
355 # spawn a process to force line-buffering, otherwise curl
356 # will write 1 character at-a-time and parallel outputs
357 # mmmaaayyy llloookkk llliiikkkeee ttthhhiiisss
358 my $o = { 1 => $lei->{2}, 2 => $lei->{2} };
359 my $pid = spawn(['tail', '-f', $cerr->filename], undef, $o);
360 $reap_tail = PublicInbox::AutoReap->new($pid);
362 my $curl = PublicInbox::LeiCurl->new($lei, $self->{curl}) or return;
363 push @$curl, '-s', '-d', '';
364 my $each_smsg = $lei->{ovv}->ovv_each_smsg_cb($lei);
365 $self->{import_sto} = $lei->{sto} if $lei->{opt}->{'import-remote'};
366 for my $uri (@$uris) {
367 $lei->{-current_url} = $uri->as_string;
368 $lei->{-nr_remote_eml} = 0;
370 my ($q, $key) = fudge_qstr_time($lei, $uri, $qstr);
371 $uri->query_form(@qform, q => $q);
372 my $cmd = $curl->for_uri($lei, $uri);
373 $lei->qerr("# $cmd");
374 my ($fh, $pid) = popen_rd($cmd, undef, $rdr);
375 my $reap_curl = PublicInbox::AutoReap->new($pid);
376 $fh = IO::Uncompress::Gunzip->new($fh, MultiStream => 1);
377 PublicInbox::MboxReader->mboxrd($fh, \&each_remote_eml, $self,
379 if ($self->{import_sto} && delete($self->{-imported})) {
380 my $wait = $self->{import_sto}->wq_do('done');
384 # don't update if no results, maybe MTA is down
385 my $nr = $lei->{-nr_remote_eml};
386 $lei->{lss}->cfg_set($key, $start) if $key && $nr;
387 mset_progress($lei, $lei->{-current_url}, $nr, $nr);
392 seek($cerr, 0, SEEK_SET) //
393 warn "seek($cmd stderr): $!";
394 $err = do { local $/; <$cerr> } //
395 warn "read($cmd stderr): $!";
396 truncate($cerr, 0) // warn "truncate($cmd stderr): $!";
399 next if (($? >> 8) == 22 && $err =~ /\b404\b/);
400 $uri->query_form(q => $qstr);
401 $lei->child_error($?, "E: <$uri> $err");
404 $lei->{ovv}->ovv_atexit_child($lei);
407 sub git { $_[0]->{git} // die 'BUG: git uninitialized' }
409 sub xsearch_done_wait { # dwaitpid callback
410 my ($arg, $pid) = @_;
411 my ($wq, $lei) = @$arg;
414 return $lei->child_error($?) if $s == 13 || $s == 15;
415 $lei->child_error($?, 'non-fatal error from '.ref($wq)." \$?=$?");
418 sub query_done { # EOF callback for main daemon
420 local $PublicInbox::LEI::current_lei = $lei;
422 my $l2m = delete $lei->{l2m};
424 ($lei->{opt}->{'mail-sync'} && !$lei->{sto}) and
425 warn "BUG: {sto} missing with --mail-sync";
426 $lei->sto_done_request if $lei->{sto};
427 if (my $v2w = delete $lei->{v2w}) {
428 my $wait = $v2w->wq_do('done'); # may die
431 $lei->{ovv}->ovv_end($lei);
432 if ($l2m) { # close() calls LeiToMail reap_compress
433 if (my $out = delete $lei->{old_1}) {
434 if (my $mbout = $lei->{1}) {
435 close($mbout) or die <<"";
436 Error closing $lei->{ovv}->{dst}: \$!=$! \$?=$?
441 if ($l2m->lock_free) {
444 } else { # mbox users
445 delete $l2m->{mbl}; # drop dotlock
448 if ($lei->{-progress}) {
449 my $tot = $lei->{-mset_total} // 0;
450 my $nr = $lei->{-nr_write} // 0;
452 my $m = "# $nr written to " .
453 "$lei->{ovv}->{dst} ($tot matches)";
454 $nr ? $lei->qfin($m) : $lei->qerr($m);
456 $lei->qerr("# $tot matches");
459 $lei->start_mua if $l2m && !$l2m->lock_free;
462 $lei->fail($@) if $@;
465 sub do_post_augment {
467 local $PublicInbox::LEI::current_lei = $lei;
468 my $l2m = $lei->{l2m} or return; # client disconnected
471 $l2m->post_augment($lei);
475 if (my $lxs = delete $lei->{lxs}) {
476 $lxs->wq_kill('-TERM');
481 if (!$err && delete $lei->{early_mua}) { # non-augment case
482 eval { $lei->start_mua };
483 $lei->fail($@) if $@;
485 close(delete $lei->{au_done}); # triggers wait_startq in lei_xsearch
488 sub incr_post_augment { # called whenever an l2m shard finishes augment
490 my $l2m = $lei->{l2m} or return; # client disconnected
491 return if ++$lei->{nr_post_augment} != $l2m->{-wq_nr_workers};
492 do_post_augment($lei);
495 my $MAX_PER_HOST = 4;
498 my ($self, $opt) = @_;
499 my $nl = $opt->{threads} ? locals($self) : 1;
500 my $nr = remotes($self);
501 $nr = $MAX_PER_HOST if $nr > $MAX_PER_HOST;
505 sub start_query ($$) { # always runs in main (lei-daemon) process
506 my ($self, $lei) = @_;
507 local $PublicInbox::LEI::current_lei = $lei;
508 if ($self->{opt_threads} || ($lei->{l2m} && !$self->{opt_sort})) {
509 for my $ibxish (locals($self)) {
510 $self->wq_io_do('query_one_mset', [], $ibxish);
512 } elsif (locals($self)) {
513 $self->wq_io_do('query_combined_mset', []);
517 for my $uri (remotes($self)) {
518 push @{$q->[$i++ % $MAX_PER_HOST]}, $uri;
521 $self->wq_io_do('query_remote_mboxrd', [], $uris);
523 if ($self->{-do_lcat}) {
524 $self->wq_io_do('lcat_dump', []);
526 $self->wq_close; # lei_xsearch workers stop when done
529 sub incr_start_query { # called whenever an l2m shard starts do_post_auth
530 my ($self, $lei) = @_;
531 my $l2m = $lei->{l2m};
532 return if ++$self->{nr_start_query} != $l2m->{-wq_nr_workers};
533 start_query($self, $lei);
536 sub ipc_atfork_child {
538 $self->{lei}->_lei_atfork_child;
539 $self->SUPER::ipc_atfork_child;
543 my ($self, $lei) = @_;
544 my $l2m = $lei->{l2m};
546 'sigpipe_handler' => [ $lei ],
547 'fail_handler' => [ $lei ],
548 'do_post_augment' => [ \&do_post_augment, $lei ],
549 'incr_post_augment' => [ \&incr_post_augment, $lei ],
550 '' => [ \&query_done, $lei ],
551 'mset_progress' => [ \&mset_progress, $lei ],
552 'l2m_progress' => [ \&l2m_progress, $lei ],
554 'child_error' => [ $lei ],
555 'incr_start_query' => [ $self, $lei ],
557 $lei->{auth}->op_merge($ops, $l2m, $lei) if $l2m && $lei->{auth};
558 my $end = $lei->pkt_op_pair;
559 $lei->{1}->autoflush(1);
560 $lei->start_pager if delete $lei->{need_pager};
561 $lei->{ovv}->ovv_begin($lei);
562 die 'BUG: xdb|over open' if $lei->{lse}->{xdb} || $lei->{lse}->{over};
564 $l2m->pre_augment($lei);
565 if ($lei->{opt}->{augment} && delete $lei->{early_mua}) {
568 my $F_SETPIPE_SZ = $^O eq 'linux' ? 1031 : undef;
569 if ($l2m->{-wq_nr_workers} > 1 &&
570 $l2m->{base_type} =~ /\A(?:maildir|mbox)\z/) {
571 # setup two barriers to coordinate ->has_entries
572 # between l2m workers
573 pipe(my ($a_r, $a_w)) or die "pipe: $!";
574 fcntl($a_r, $F_SETPIPE_SZ, 4096) if $F_SETPIPE_SZ;
575 pipe(my ($b_r, $b_w)) or die "pipe: $!";
576 fcntl($b_r, $F_SETPIPE_SZ, 4096) if $F_SETPIPE_SZ;
577 $l2m->{au_peers} = [ $a_r, $a_w, $b_r, $b_w ];
579 $l2m->wq_workers_start('lei2mail', undef,
580 $lei->oldset, { lei => $lei });
581 $l2m->wq_wait_async(\&xsearch_done_wait, $lei);
582 pipe($lei->{startq}, $lei->{au_done}) or die "pipe: $!";
583 fcntl($lei->{startq}, $F_SETPIPE_SZ, 4096) if $F_SETPIPE_SZ;
584 delete $l2m->{au_peers};
586 $self->wq_workers_start('lei_xsearch', undef,
587 $lei->oldset, { lei => $lei });
588 $self->wq_wait_async(\&xsearch_done_wait, $lei);
589 my $op_c = delete $lei->{pkt_op_c};
590 delete $lei->{pkt_op_p};
592 $self->{opt_threads} = $lei->{opt}->{threads};
593 $self->{opt_sort} = $lei->{opt}->{'sort'};
594 $self->{-do_lcat} = !!(delete $lei->{lcat_todo});
596 $l2m->net_merge_all_done($lei) unless $lei->{auth};
598 start_query($self, $lei);
600 $lei->event_step_init; # wait for shutdowns
601 $lei->wait_wq_events($op_c, $ops);
605 my ($self, $uri) = @_;
606 if (my $curl = $self->{curl} //= which('curl') // 0) {
607 require PublicInbox::MboxReader;
608 require IO::Uncompress::Gunzip;
609 require PublicInbox::LeiCurl;
610 push @{$self->{remotes}}, $uri;
612 warn "curl missing, ignoring $uri\n";
616 sub prepare_external {
617 my ($self, $loc, $boost) = @_; # n.b. already ordered by boost
618 if (ref $loc) { # already a URI, or PublicInbox::Inbox-like object
619 return add_uri($self, $loc) if $loc->can('scheme');
620 } elsif ($loc =~ m!\Ahttps?://!) {
622 return add_uri($self, URI->new($loc));
623 } elsif (-f "$loc/ei.lock") {
624 require PublicInbox::ExtSearch;
625 die "`\\n' not allowed in `$loc'\n" if index($loc, "\n") >= 0;
626 $loc = PublicInbox::ExtSearch->new($loc);
627 } elsif (-f "$loc/inbox.lock" || -d "$loc/public-inbox") {
628 die "`\\n' not allowed in `$loc'\n" if index($loc, "\n") >= 0;
629 require PublicInbox::Inbox; # v2, v1
630 $loc = bless { inboxdir => $loc }, 'PublicInbox::Inbox';
632 warn "W: $loc gone, perhaps run: lei forget-external $loc\n";
635 warn "W: $loc ignored, unable to determine external type\n";
638 push @{$self->{locals}}, $loc;
641 sub _lcat_i { # LeiMailSync->each_src iterator callback
642 my ($oidbin, $id, $each_smsg) = @_;
643 $each_smsg->({blob => unpack('H*', $oidbin), pct => 100});
646 sub _lcat2smsg { # git->cat_async callback
647 my ($bref, $oid, $type, $size, $smsg) = @_;
649 my $eml = PublicInbox::Eml->new($bref);
650 my $json_dump = delete $smsg->{-json_dump};
651 bless $smsg, 'PublicInbox::Smsg';
652 _smsg_fill($smsg, $eml);
653 $json_dump->($smsg, undef, $eml);
657 sub lcat_dump { # via wq_io_do
659 my $lei = $self->{lei};
660 my $each_smsg = $lei->{ovv}->ovv_each_smsg_cb($lei);
661 my $git = $lei->{ale}->git;
663 my $json_dump = $each_smsg;
666 $smsg->{-json_dump} = $json_dump;
667 $git->cat_async($smsg->{blob}, \&_lcat2smsg, $smsg);
671 for my $ent (@{$lei->{lcat_todo}}) {
672 if (ref $ent eq 'HASH') { # { fid => $fid ,.. }
673 $lms //= $lei->{lse}->lms;
674 $lms->each_src($ent, \&_lcat_i, $each_smsg);
676 $each_smsg->({ blob => $ent, pct => 100 });
679 $git->async_wait_all;
680 undef $each_smsg; # may commit
681 $lei->{ovv}->ovv_atexit_child($lei);