From 4caa17ef5aa8554d78b8c013096f12429c58e050 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 2 Aug 2016 08:32:09 +0000 Subject: search: improve reindexing behavior For reindexing, fresh Xapian DBs do not count as a reindex, allowing users to blindly use --reindex on the first run on a clean repo. While we're at it, allow indexing to override HEAD ref for multi-head git repos. --- lib/PublicInbox/SearchIdx.pm | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'lib/PublicInbox/SearchIdx.pm') diff --git a/lib/PublicInbox/SearchIdx.pm b/lib/PublicInbox/SearchIdx.pm index 6a34ce71..f0a3687d 100644 --- a/lib/PublicInbox/SearchIdx.pm +++ b/lib/PublicInbox/SearchIdx.pm @@ -374,7 +374,7 @@ sub rlog { # indexes all unindexed messages sub _index_sync { my ($self, $opts) = @_; - my $head = 'HEAD'; + my $tip = $opts->{ref} || 'HEAD'; my $mm = $self->{mm} = eval { require PublicInbox::Msgmap; PublicInbox::Msgmap->new($self->{git_dir}, 1); @@ -382,8 +382,13 @@ sub _index_sync { my $xdb = $self->{xdb}; $xdb->begin_transaction; my $reindex = $opts->{reindex}; - my $mkey = $reindex ? undef : 'last_commit'; - my $lx = $reindex ? '' : $xdb->get_metadata('last_commit'); + my $mkey = 'last_commit'; + my $last_commit = $xdb->get_metadata($mkey); + my $lx = $last_commit; + if ($reindex) { + $lx = ''; + $mkey = undef if $last_commit ne ''; + } my $dbh; my $cb = sub { my ($commit, $more) = @_; @@ -398,7 +403,7 @@ sub _index_sync { $xdb = _xdb_acquire($self); }; - my $range = $lx eq '' ? $head : "$lx..$head"; + my $range = $lx eq '' ? $tip : "$lx..$tip"; if ($mm) { $dbh = $mm->{dbh}; $dbh->begin_work; @@ -413,14 +418,15 @@ sub _index_sync { # This happens if we have to reindex Xapian since # msgmap is a frozen format and our Xapian format # is evolving. - my $r = $lm eq '' ? $head : "$lm..$head"; + my $r = $lm eq '' ? $tip : "$lm..$tip"; # first, ensure msgmap is up-to-date: + my $mkey_prev = $mkey; $mkey = undef; # ignore xapian, for now rlog($self, $r, *index_mm, *unindex_mm, $cb); # now deal with Xapian - $mkey = 'last_commit' unless $reindex; + $mkey = $mkey_prev; $dbh = undef; rlog($self, $range, *index_mm2, *unindex_mm2, $cb); } -- cgit v1.2.3-24-ge0c7