]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/SearchIdxShard.pm
favor readline() and print() as functions
[public-inbox.git] / lib / PublicInbox / SearchIdxShard.pm
index 1ea01095c4fa6829fd6dc914cefdb0da3dc23f24..c1f52d8b884fd7e723275f8e8c259aaf2ace4092 100644 (file)
@@ -8,6 +8,7 @@ use strict;
 use warnings;
 use base qw(PublicInbox::SearchIdx);
 use IO::Handle (); # autoflush
+use PublicInbox::Eml;
 
 sub new {
        my ($class, $v2writable, $shard) = @_;
@@ -52,7 +53,7 @@ sub shard_worker_loop ($$$$$) {
        my ($self, $v2w, $r, $shard, $bnote) = @_;
        $0 = "pi-v2-shard[$shard]";
        $self->begin_txn_lazy;
-       while (my $line = $r->getline) {
+       while (my $line = readline($r)) {
                $v2w->{current_info} = "[$shard] $line";
                if ($line eq "commit\n") {
                        $self->commit_txn_lazy;
@@ -69,12 +70,13 @@ sub shard_worker_loop ($$$$$) {
                        $self->remove_by_oid($oid, $mid);
                } else {
                        chomp $line;
-                       my ($bytes, $num, $blob, $mid, $ds, $ts) =
-                                                       split(/ /, $line);
+                       # n.b. $mid may contain spaces(!)
+                       my ($bytes, $num, $blob, $ds, $ts, $mid) =
+                                                       split(/ /, $line, 6);
                        $self->begin_txn_lazy;
                        my $n = read($r, my $msg, $bytes) or die "read: $!\n";
                        $n == $bytes or die "short read: $n != $bytes\n";
-                       my $mime = PublicInbox::MIME->new(\$msg);
+                       my $mime = PublicInbox::Eml->new(\$msg);
                        my $smsg = bless {
                                bytes => $bytes,
                                num => $num + 0,
@@ -93,7 +95,8 @@ sub shard_worker_loop ($$$$$) {
 sub index_raw {
        my ($self, $msgref, $mime, $smsg) = @_;
        if (my $w = $self->{w}) {
-               print $w join(' ', @$smsg{qw(bytes num blob mid ds ts)}),
+               # mid must be last, it can contain spaces (but not LF)
+               print $w join(' ', @$smsg{qw(bytes num blob ds ts mid)}),
                        "\n", $$msgref or die "failed to write shard $!\n";
        } else {
                $$msgref = undef;