about summary refs log tree commit homepage
path: root/lib/PublicInbox/LeiStore.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-03-14 13:12:00 +0200
committerEric Wong <e@80x24.org>2021-03-15 08:04:44 +0000
commit42fc590f8cabd23455949d002e2ddf28bbec6d1e (patch)
treecf521b1325e9d74d60ad5f75d0df1d12cf277cb0 /lib/PublicInbox/LeiStore.pm
parent64b557420689476493d752968d99ab8ae62bad9a (diff)
downloadpublic-inbox-42fc590f8cabd23455949d002e2ddf28bbec6d1e.tar.gz
We only want to auto import messages that are exclusively in
remote externals.  Messages in local externals are not
auto-imported to save space and reduce wear on storage device.
Diffstat (limited to 'lib/PublicInbox/LeiStore.pm')
-rw-r--r--lib/PublicInbox/LeiStore.pm52
1 files changed, 46 insertions, 6 deletions
diff --git a/lib/PublicInbox/LeiStore.pm b/lib/PublicInbox/LeiStore.pm
index 6ace2ad1..aaee5874 100644
--- a/lib/PublicInbox/LeiStore.pm
+++ b/lib/PublicInbox/LeiStore.pm
@@ -213,6 +213,24 @@ sub set_eml {
         add_eml($self, $eml, @kw) // set_eml_keywords($self, $eml, @kw);
 }
 
+sub add_eml_maybe {
+        my ($self, $eml) = @_;
+        my $lxs = $self->{lxs_all_local} // die 'BUG: no {lxs_all_local}';
+        return if $lxs->xids_for($eml, 1);
+        add_eml($self, $eml);
+}
+
+# set or update keywords for external message, called via ipc_do
+sub set_xkw {
+        my ($self, $eml, $kw) = @_;
+        my $lxs = $self->{lxs_all_local} // die 'BUG: no {lxs_all_local}';
+        if ($lxs->xids_for($eml, 1)) { # is it in a local external?
+                # TODO: index keywords only
+        } else {
+                set_eml($self, $eml, @$kw);
+        }
+}
+
 sub checkpoint {
         my ($self, $wait) = @_;
         if (my $im = $self->{im}) {
@@ -237,18 +255,40 @@ sub done {
 
 sub ipc_atfork_child {
         my ($self) = @_;
-        my $lei = delete $self->{lei};
+        my $lei = $self->{lei};
         $lei->lei_atfork_child(1) if $lei;
         $self->SUPER::ipc_atfork_child;
 }
 
+sub refresh_local_externals {
+        my ($self) = @_;
+        my $cfg = $self->{lei}->_lei_cfg or return;
+        my $cur_cfg = $self->{cur_cfg} // -1;
+        my $lxs = $self->{lxs_all_local};
+        if ($cfg != $cur_cfg || !$lxs) {
+                $lxs = PublicInbox::LeiXSearch->new;
+                my @loc = $self->{lei}->externals_each;
+                for my $loc (@loc) { # locals only
+                        $lxs->prepare_external($loc) if -d $loc;
+                }
+                $self->{lxs_all_local} = $lxs;
+                $self->{cur_cfg} = $cfg;
+        }
+        ($lxs->{git_tmp} //= $lxs->git_tmp)->{git_dir};
+}
+
 sub write_prepare {
         my ($self, $lei) = @_;
-        $self->ipc_lock_init;
-        # Mail we import into lei are private, so headers filtered out
-        # by -mda for public mail are not appropriate
-        local @PublicInbox::MDA::BAD_HEADERS = ();
-        $self->ipc_worker_spawn('lei_store', $lei->oldset, { lei => $lei });
+        unless ($self->{-ipc_req}) {
+                require PublicInbox::LeiXSearch;
+                $self->ipc_lock_init;
+                # Mail we import into lei are private, so headers filtered out
+                # by -mda for public mail are not appropriate
+                local @PublicInbox::MDA::BAD_HEADERS = ();
+                $self->ipc_worker_spawn('lei_store', $lei->oldset,
+                                        { lei => $lei });
+        }
+        $lei->{all_ext_git_dir} = $self->ipc_do('refresh_local_externals');
         $lei->{sto} = $self;
 }