diff --git a/backend/explore/explore.go b/backend/explore/explore.go index c43536c..9a91ad3 100644 --- a/backend/explore/explore.go +++ b/backend/explore/explore.go @@ -48,6 +48,7 @@ func NewExploreService(logger *slog.Logger, db *database.DB) *Service { db, cache, mbBackgroundLimiter, logger.WithGroup("artist-image"), ) index := NewSearchIndex(db, lb, artistImg, logger.WithGroup("search-index")) + index.MarkReadyIfPopulated() // make index queryable immediately if data exists libMBID := NewLibraryMBIDIndex(db) logger.Info("explore service created") diff --git a/backend/explore/searchindex.go b/backend/explore/searchindex.go index 32ffa1c..e402c73 100644 --- a/backend/explore/searchindex.go +++ b/backend/explore/searchindex.go @@ -508,7 +508,7 @@ func (si *SearchIndex) build(ctx context.Context) { si.logger.Info("search index build starting") // Mark ready from existing rows so search works during the build. - si.markReadyIfPopulated() + si.MarkReadyIfPopulated() indexLimiter := NewRateLimiterN(indexerRate) indexLB := NewListenBrainzClient(indexLimiter, si.lb.cache, si.logger.WithGroup("indexer")) @@ -1609,7 +1609,10 @@ func (si *SearchIndex) setMeta(key, value string) { } } -func (si *SearchIndex) markReadyIfPopulated() { +// MarkReadyIfPopulated sets the index as ready for querying if it +// already contains data from a previous build. Called eagerly at +// service creation so the index is queryable before StartBuild runs. +func (si *SearchIndex) MarkReadyIfPopulated() { rows, err := si.db.QueryContext("SELECT COUNT(*) FROM explore_index") if err != nil { return