]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/V2Writable.pm
v2: generate better Message-IDs for duplicates
[public-inbox.git] / lib / PublicInbox / V2Writable.pm
index 53fdb738621964171fa5a5aedb78b7ed17ccebb2..0dcdedae54c914675559733b5364255c34206c41 100644 (file)
@@ -22,8 +22,11 @@ use IO::Handle;
 my $PACKING_FACTOR = 0.4;
 
 # assume 2 cores if GNU nproc(1) is not available
-sub nproc () {
-       int($ENV{NPROC} || `nproc 2>/dev/null` || 2);
+sub nproc_parts () {
+       my $n = int($ENV{NPROC} || `nproc 2>/dev/null` || 2);
+       # subtract for the main process and git-fast-import
+       $n -= 1;
+       $n < 1 ? 1 : $n;
 }
 
 sub count_partitions ($) {
@@ -73,7 +76,7 @@ sub new {
                rotate_bytes => int((1024 * 1024 * 1024) / $PACKING_FACTOR),
                last_commit => [], # git repo -> commit
        };
-       $self->{partitions} = count_partitions($self) || nproc();
+       $self->{partitions} = count_partitions($self) || nproc_parts();
        bless $self, $class;
 }
 
@@ -171,19 +174,19 @@ sub num_for_harder {
 
        my $hdr = $mime->header_obj;
        my $dig = content_digest($mime);
-       $$mid0 = PublicInbox::Import::digest2mid($dig);
+       $$mid0 = PublicInbox::Import::digest2mid($dig, $hdr);
        my $num = $self->{mm}->mid_insert($$mid0);
        unless (defined $num) {
                # it's hard to spoof the last Received: header
                my @recvd = $hdr->header_raw('Received');
                $dig->add("Received: $_") foreach (@recvd);
-               $$mid0 = PublicInbox::Import::digest2mid($dig);
+               $$mid0 = PublicInbox::Import::digest2mid($dig, $hdr);
                $num = $self->{mm}->mid_insert($$mid0);
 
                # fall back to a random Message-ID and give up determinism:
                until (defined($num)) {
                        $dig->add(rand);
-                       $$mid0 = PublicInbox::Import::digest2mid($dig);
+                       $$mid0 = PublicInbox::Import::digest2mid($dig, $hdr);
                        warn "using random Message-ID <$$mid0> as fallback\n";
                        $num = $self->{mm}->mid_insert($$mid0);
                }
@@ -800,7 +803,7 @@ sub unindex_oid {
                my %gone;
                my ($id, $prev);
                while (my $smsg = $over->next_by_mid($mid, \$id, \$prev)) {
-                       $gone{$smsg->num} = 1 if $oid eq $smsg->{blob};
+                       $gone{$smsg->{num}} = 1 if $oid eq $smsg->{blob};
                        1; # continue
                }
                my $n = scalar keys %gone;