-# only for a few odd messages with multiple Message-IDs
-sub reindex_oid_m ($$$$;$) {
- my ($self, $sync, $git, $oid, $regen_num) = @_;
- $self->{current_info} = "multi_mid $oid";
- my ($num, $mid0, $len);
- my $msgref = $git->cat_file($oid, \$len);
- my $mime = PublicInbox::MIME->new($$msgref);
- my $mids = mids($mime->header_obj);
- my $cid = content_id($mime);
- die "BUG: reindex_oid_m called for <=1 mids" if scalar(@$mids) <= 1;
-
- for my $mid (reverse @$mids) {
- delete($sync->{D}->{"$mid\0$cid"}) and
- die "BUG: reindex_oid should handle <$mid> delete";
- }
- my $over = $self->{over};
- for my $mid (reverse @$mids) {
- ($num, $mid0) = $over->num_mid0_for_oid($oid, $mid);
- next unless defined $num;
- if (defined($regen_num) && $regen_num != $num) {
- die "BUG: regen(#$regen_num) != over(#$num)";
- }
- }
- unless (defined($num)) {
- for my $mid (reverse @$mids) {
- # is this a number we got before?
- my $n = $sync->{mm_tmp}->num_for($mid);
- next unless defined $n;
- next if defined($regen_num) && $regen_num != $n;
- ($num, $mid0) = ($n, $mid);
- last;
- }
- }
- if (defined($num)) {
- $sync->{mm_tmp}->num_delete($num);
- } elsif (defined $regen_num) {
- $num = $regen_num;
- for my $mid (reverse @$mids) {
- $self->{mm}->mid_set($num, $mid) == 1 or next;
- $mid0 = $mid;
- last;
- }
- unless (defined $mid0) {
- warn "E: cannot regen #$num\n";
- return;
- }
- } else { # fixup bugs in old mirrors on reindex
- for my $mid (reverse @$mids) {
- $num = $self->{mm}->mid_insert($mid);
- next unless defined $num;
- $mid0 = $mid;
- last;
- }
- if (defined $mid0) {
- if ($sync->{reindex}) {
- warn "reindex added #$num <$mid0>\n";
- }
- } else {
- warn "E: cannot find article #\n";
- return;
- }
- }
- $sync->{nr}++;
- if (do_idx($self, $msgref, $mime, $len, $num, $oid, $mid0)) {
- reindex_checkpoint($self, $sync, $git);
- }
-}
-
-sub check_unindexed ($$$) {
- my ($self, $num, $mid0) = @_;
- my $unindexed = $self->{unindexed} // {};
- my $n = delete($unindexed->{$mid0});
- defined $n or return;
- if ($n != $num) {
- die "BUG: unindexed $n != $num <$mid0>\n";
- } else {
- $self->{mm}->mid_set($num, $mid0);
- }
-}
-
-# reuse Msgmap to store num => oid mapping (rather than num => mid)
-sub multi_mid_q_new () {
- my ($fh, $fn) = tempfile('multi_mid-XXXXXXX', EXLOCK => 0, TMPDIR => 1);
- my $multi_mid = PublicInbox::Msgmap->new_file($fn, 1);
- $multi_mid->{dbh}->do('PRAGMA synchronous = OFF');
- # for Msgmap->DESTROY:
- $multi_mid->{tmp_name} = $fn;
- $multi_mid->{pid} = $$;
- close $fh or die "failed to close $fn: $!";
- $multi_mid
-}
-
-sub multi_mid_q_push ($$) {
- my ($sync, $oid) = @_;
- my $multi_mid = $sync->{multi_mid} //= multi_mid_q_new();
- if ($sync->{reindex}) { # no regen on reindex
- $multi_mid->mid_insert($oid);
- } else {
- my $num = $sync->{regen}--;
- die "BUG: ran out of article numbers" if $num <= 0;
- $multi_mid->mid_set($num, $oid);
- }
-}
-
-sub reindex_oid ($$$$) {
- my ($self, $sync, $git, $oid) = @_;
- my ($num, $mid0, $len);
- my $msgref = $git->cat_file($oid, \$len);
- return if $len == 0; # purged
- my $mime = PublicInbox::MIME->new($$msgref);
- my $mids = mids($mime->header_obj);
- my $cid = content_id($mime);