]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/LeiStore.pm
lei_store: add ->set_eml, ->add_eml can return smsg
[public-inbox.git] / lib / PublicInbox / LeiStore.pm
index a17c7bab423d26c90055a54fe6b0fa0731707bdc..43fddf6deb8176e16cdc29187118b94e05d45dfc 100644 (file)
@@ -9,7 +9,7 @@
 package PublicInbox::LeiStore;
 use strict;
 use v5.10.1;
-use parent qw(PublicInbox::Lock);
+use parent qw(PublicInbox::Lock PublicInbox::IPC);
 use PublicInbox::SearchIdx qw(crlf_adjust);
 use PublicInbox::ExtSearchIdx;
 use PublicInbox::Import;
@@ -60,24 +60,6 @@ sub git_ident ($) {
                ('lei user', 'x@example.com')
 }
 
-# We will support users combining storage across multiple machines
-# somehow.  Use per-machine refnames to make it easy-to-identify
-# where a message came from
-sub host_head () {
-       state $h = do {
-               my $x = PublicInbox::ExtSearchIdx::host_ident;
-               # Similar rules found in git.git/remote.c::valid_remote_nick
-               # and git.git/refs.c::check_refname_component
-               $x =~ s!(?:\.lock|/)+\z!!gs; # must not end with ".lock" or "/"
-               $x =~ tr/././s; # no dot-dot, collapse them
-               $x =~ s/@\{/\@-/gs;
-               $x =~ s/\A\./-/s;
-               # no "*", ":", "?", "[", "\", "^", "~", SP, TAB; "]" is OK
-               $x =~ tr^a-zA-Z0-9!"#$%&'()+,\-.;<=>@]_`{|}^-^c;
-               $x
-       };
-}
-
 sub importer {
        my ($self) = @_;
        my $max;
@@ -96,7 +78,7 @@ sub importer {
        while (1) {
                my $latest = "$pfx/$max.git";
                my $old = -e $latest;
-               PublicInbox::Import::init_bare($latest, host_head);
+               PublicInbox::Import::init_bare($latest);
                my $git = PublicInbox::Git->new($latest);
                $git->qx(qw(config core.sharedRepository 0600)) if !$old;
                my $packed_bytes = $git->packed_bytes;
@@ -110,7 +92,6 @@ sub importer {
                $im->{bytes_added} = int($packed_bytes / $self->packing_factor);
                $im->{lock_path} = undef;
                $im->{path_type} = 'v2';
-               $im->{'ref'} = host_head;
                return $im;
        }
 }
@@ -218,6 +199,7 @@ sub add_eml {
                        $idx->shard_add_eidx_info($docid, '.', $eml); # List-Id
                        $idx->shard_add_keywords($docid, @kw) if @kw;
                }
+               \@docids;
        } else {
                $smsg->{num} = $oidx->adj_counter('eidx_docid', '+');
                $oidx->add_overview($eml, $smsg);
@@ -225,8 +207,13 @@ sub add_eml {
                my $idx = $eidx->idx_shard($smsg->{num});
                $idx->index_raw($msgref, $eml, $smsg);
                $idx->shard_add_keywords($smsg->{num}, @kw) if @kw;
+               $smsg;
        }
-       $smsg->{blob}
+}
+
+sub set_eml {
+       my ($self, $eml, @kw) = @_;
+       add_eml($self, $eml, @kw) // set_eml_keywords($self, $eml, @kw);
 }
 
 sub done {