]> Sergey Matveev's repositories - public-inbox.git/blob - lib/PublicInbox/LeiReindex.pm
No ext_urls
[public-inbox.git] / lib / PublicInbox / LeiReindex.pm
1 # Copyright all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
3
4 # "lei reindex" command to reindex everything in lei/store
5 package PublicInbox::LeiReindex;
6 use v5.12;
7 use parent qw(PublicInbox::IPC);
8
9 sub reindex_full {
10         my ($lei) = @_;
11         my $sto = $lei->{sto};
12         my $max = $sto->search->over(1)->max;
13         $lei->qerr("# reindexing 1..$max");
14         $sto->wq_do('reindex_art', $_) for (1..$max);
15 }
16
17 sub reindex_store { # via wq_do
18         my ($self) = @_;
19         my ($lei, $argv) = delete @$self{qw(lei argv)};
20         if (!@$argv) {
21                 reindex_full($lei);
22         }
23 }
24
25 sub lei_reindex {
26         my ($lei, @argv) = @_;
27         my $sto = $lei->_lei_store or return $lei->fail('nothing indexed');
28         $sto->write_prepare($lei);
29         my $self = bless { lei => $lei, argv => \@argv }, __PACKAGE__;
30         my ($op_c, $ops) = $lei->workers_start($self, 1);
31         $lei->{wq1} = $self;
32         $lei->wait_wq_events($op_c, $ops);
33         $self->wq_do('reindex_store');
34         $self->wq_close;
35 }
36
37 sub _lei_wq_eof { # EOF callback for main lei daemon
38         my ($lei) = @_;
39         $lei->{sto}->wq_do('reindex_done');
40         $lei->wq_eof;
41 }
42
43 sub ipc_atfork_child {
44         my ($self) = @_;
45         $self->{lei}->_lei_atfork_child;
46         $self->SUPER::ipc_atfork_child;
47 }
48
49 1;