From 40f3f2a2c805fc37c7ed35a60948856bd962b493 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 4 May 2021 09:49:12 +0000 Subject: lei index: new command to index mail w/o git storage 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. --- lib/PublicInbox/FakeImport.pm | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 lib/PublicInbox/FakeImport.pm (limited to 'lib/PublicInbox/FakeImport.pm') diff --git a/lib/PublicInbox/FakeImport.pm b/lib/PublicInbox/FakeImport.pm new file mode 100644 index 00000000..dea25cbe --- /dev/null +++ b/lib/PublicInbox/FakeImport.pm @@ -0,0 +1,23 @@ +# Copyright (C) 2021 all contributors +# License: AGPL-3.0+ + +# pretend to do PublicInbox::Import::add for "lei index" +package PublicInbox::FakeImport; +use strict; +use PublicInbox::ContentHash qw(git_sha); + +sub new { bless { bytes_added => 0 }, __PACKAGE__ } + +sub add { + my ($self, $eml, $check_cb, $smsg) = @_; + $smsg->populate($eml); + my $raw = $eml->as_string; + $smsg->{blob} = git_sha(1, \$raw)->hexdigest; + $smsg->set_bytes($raw, length($raw)); + if (my $oidx = delete $smsg->{-oidx}) { # used by LeiStore + $oidx->vivify_xvmd($smsg) or return; + } + 1; +} + +1; -- cgit v1.2.3-24-ge0c7