about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2023-11-30 21:40:47 +0000
committerEric Wong <e@80x24.org>2023-11-30 21:41:05 +0000
commit675efa2ea250f061aac26fd11dd61f25f21d9b29 (patch)
treedaf78fc6850434de929a892b792c478a86ff0261
parent2e3d2fdcad7181b8b4a8893023d4819a25e54ba1 (diff)
downloadpublic-inbox-675efa2ea250f061aac26fd11dd61f25f21d9b29.tar.gz
As with mail search, a cindex may be updated while WWW is
serving requests.  Thus we must reopen the Xapian DB when
the revision we're using becomes stale.
-rw-r--r--lib/PublicInbox/CodeSearch.pm16
1 files changed, 6 insertions, 10 deletions
diff --git a/lib/PublicInbox/CodeSearch.pm b/lib/PublicInbox/CodeSearch.pm
index f4694686..3092718d 100644
--- a/lib/PublicInbox/CodeSearch.pm
+++ b/lib/PublicInbox/CodeSearch.pm
@@ -258,15 +258,11 @@ sub load_ct { # retry_reopen cb
 
 sub load_commit_times { # each_cindex callback
         my ($self, $todo) = @_; # todo = [ [ time, git ], [ time, git ] ...]
-        my (@pending, $rec, $dir, @ids, $doc);
+        my (@pending, $rec, $ct);
         while ($rec = shift @$todo) {
-                @ids = docids_of_git_dir $self, $rec->[1]->{git_dir};
-                if (@ids) {
-                        for (@ids) {
-                                $doc = $self->get_doc($_) // next;
-                                $rec->[0] = int_val($doc, CT);
-                                last;
-                        }
+                $ct = $self->retry_reopen(\&load_ct, $rec->[1]->{git_dir});
+                if (defined $ct) {
+                        $rec->[0] = $ct;
                 } else { # may be in another cindex:
                         push @pending, $rec;
                 }
@@ -295,7 +291,7 @@ EOM
                         $git;
                 };
         }
-        my $jd = join_data($self) or return warn <<EOM;
+        my $jd = $self->retry_reopen(\&join_data, $self) or return warn <<EOM;
 W: cindex.$name.topdir=$self->{topdir} has no usable join data for $cfg_f
 EOM
         my ($ekeys, $roots, $ibx2root) = @$jd{qw(ekeys roots ibx2root)};
@@ -366,7 +362,7 @@ sub repos_sorted {
         my @recs = map { [ 0, $_ ] } @_; # PublicInbox::Git objects
         my @todo = @recs;
         $pi_cfg->each_cindex(\&load_commit_times, \@todo);
-        @recs = sort { $b->[0] <=> $a->[0] } @recs;
+        @recs = sort { $b->[0] <=> $a->[0] } @recs; # sort by commit time
 }
 
 1;