about summary refs log tree commit homepage
path: root/lib/PublicInbox/LeiIndex.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-05-04 09:49:12 +0000
committerEric Wong <e@80x24.org>2021-05-04 23:08:01 +0000
commit40f3f2a2c805fc37c7ed35a60948856bd962b493 (patch)
tree0fe4d70c7a50a0122f92d48b832ada31a3b5a0bf /lib/PublicInbox/LeiIndex.pm
parent4481b372ba150c669b2fefe2d6ec5dccb5da1d40 (diff)
downloadpublic-inbox-40f3f2a2c805fc37c7ed35a60948856bd962b493.tar.gz
Since completely purging blobs from git is slow, users may wish
to index messages in Maildirs (and eventually other local
storage) without storing data in git.

Much code from LeiImport and LeiInput is reused, and a new dummy
FakeImport class supplies a non-storing $im->add and minimize
changes to LeiStore.

The tricky part of this command is to support "lei import"
after a message has gone through "lei index".  Relying on
$smsg->{bytes} == 0 (as we do for external-only vmd storage)
does not work here, since it would break searching for "z:"
byte-ranges when not using externals.

This eventually required PublicInbox::Import::add to use a
SharedKV to keep track of imported blobs and prevent
duplication.
Diffstat (limited to 'lib/PublicInbox/LeiIndex.pm')
-rw-r--r--lib/PublicInbox/LeiIndex.pm48
1 files changed, 48 insertions, 0 deletions
diff --git a/lib/PublicInbox/LeiIndex.pm b/lib/PublicInbox/LeiIndex.pm
new file mode 100644
index 00000000..cc3e83e7
--- /dev/null
+++ b/lib/PublicInbox/LeiIndex.pm
@@ -0,0 +1,48 @@
+# Copyright (C) 2021 all contributors <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+
+# front-end for the "lei index" sub-command, this is similar to
+# "lei import" but doesn't put a git blob into ~/.local/share/lei/store
+package PublicInbox::LeiIndex;
+use strict;
+use v5.10.1;
+use parent qw(PublicInbox::IPC PublicInbox::LeiInput);
+use PublicInbox::LeiImport;
+
+# /^input_/ subs are used by (or override) PublicInbox::LeiInput superclass
+sub input_eml_cb { # used by input_maildir_cb and input_net_cb
+        my ($self, $eml, $vmd) = @_;
+        my $xoids = $self->{lei}->{ale}->xoids_for($eml);
+        if (my $all_vmd = $self->{all_vmd}) {
+                @$vmd{keys %$all_vmd} = values %$all_vmd;
+        }
+        $self->{lei}->{sto}->ipc_do('index_eml_only', $eml, $vmd, $xoids);
+}
+
+sub input_fh { # overrides PublicInbox::LeiInput::input_fh
+        my ($self, $ifmt, $fh, $input, @args) = @_;
+        $self->{lei}->child_error(1<<8, <<EOM);
+$input ($ifmt) not yet supported, try `lei import'
+EOM
+}
+
+sub lei_index {
+        my ($lei, @argv) = @_;
+        $lei->{opt}->{'mail-sync'} = 1;
+        my $self = bless {}, __PACKAGE__;
+        PublicInbox::LeiImport::do_import_index($self, $lei, @argv);
+}
+
+no warnings 'once';
+no strict 'refs';
+for my $m (qw(input_maildir_cb input_net_cb)) {
+        *$m = PublicInbox::LeiImport->can($m);
+}
+
+*_complete_import = \&PublicInbox::LeiImport::_complete_import;
+*ipc_atfork_child = \&PublicInbox::LeiInput::input_only_atfork_child;
+*net_merge_all_done = \&PublicInbox::LeiInput::input_only_net_merge_all_done;
+
+# the following works even when LeiAuth is lazy-loaded
+*net_merge_all = \&PublicInbox::LeiAuth::net_merge_all;
+1;