From ea885bf0f76dc1795dc771667be721ec0fed5482 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 29 Nov 2020 05:09:35 +0000 Subject: extindex: support `--gc' to remove dead inboxes Inboxes may be removed or newsgroups renamed over time. Introduce a switch to do garbage collection and eliminate stale search and xref3 results based on inboxes which remain in the config file. This may also fixup stale results leftover from any bugs which may leave stale data around. This is also useful in case a clumsy BOFH (me :P) is swapping between several PI_CONFIGs and accidentally indexed a bunch of inboxes they didn't intend to. --- t/extsearch.t | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 't') diff --git a/t/extsearch.t b/t/extsearch.t index 4f1dbadf..10b14baf 100644 --- a/t/extsearch.t +++ b/t/extsearch.t @@ -16,7 +16,8 @@ my $host_port = $sock->sockhost . ':' . $sock->sockport; my ($home, $for_destroy) = tmpdir(); local $ENV{HOME} = $home; mkdir "$home/.public-inbox" or BAIL_OUT $!; -open my $fh, '>', "$home/.public-inbox/config" or BAIL_OUT $!; +my $cfg_path = "$home/.public-inbox/config"; +open my $fh, '>', $cfg_path or BAIL_OUT $!; print $fh <>', "$home/.public-inbox/config" or BAIL_OUT $!; + open $fh, '>>', $cfg_path or BAIL_OUT $!; print $fh <ALL [extindex "all"] @@ -148,4 +149,18 @@ is(scalar(@it), 2, 'two inboxes'); like($it[0]->get_document->get_data, qr/v2test/, 'docdata matched v2'); like($it[1]->get_document->get_data, qr/v1test/, 'docdata matched v1'); +if ('remove v1test and test gc') { + xsys([qw(git config --unset publicinbox.v1test.inboxdir)], + { GIT_CONFIG => $cfg_path }); + my $opt = { 2 => \(my $err = '') }; + ok(run_script([qw(-extindex --gc), "$home/extindex"], undef, $opt), + 'extindex --gc'); + like($err, qr/^I: remove #1 v1\.example /ms, 'removed v1 message'); + is(scalar(grep(!/^I:/, split(/^/m, $err))), 0, + 'no non-informational messages'); + $misc->{xdb}->reopen; + @it = $misc->mset('')->items; + is(scalar(@it), 1, 'only one inbox left'); +} + done_testing; -- cgit v1.2.3-24-ge0c7