user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
* [PATCH] search: improve reindexing behavior
@ 2016-08-02  8:42 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2016-08-02  8:42 UTC (permalink / raw)
  To: meta

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/Import.pm    |  3 ++-
 lib/PublicInbox/SearchIdx.pm | 18 ++++++++++++------
 2 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/lib/PublicInbox/Import.pm b/lib/PublicInbox/Import.pm
index bb0811a..b3812a6 100644
--- a/lib/PublicInbox/Import.pm
+++ b/lib/PublicInbox/Import.pm
@@ -237,7 +237,8 @@ sub done {
 
 		eval {
 			require PublicInbox::SearchIdx;
-			PublicInbox::SearchIdx->new($git_dir, 2)->index_sync;
+			my $s = PublicInbox::SearchIdx->new($git_dir, 2);
+			$s->index_sync({ ref => $self->{ref} });
 		};
 	}
 
diff --git a/lib/PublicInbox/SearchIdx.pm b/lib/PublicInbox/SearchIdx.pm
index 6a34ce7..f0a3687 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);
 		}
-- 
EW


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2016-08-02  8:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-02  8:42 [PATCH] search: improve reindexing behavior Eric Wong

Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).