feat: SearchIndex — background build + FTS5 query for popularity index
New SearchIndex struct in searchindex.go:
- Background build fetches top 1000 LB artists, then their top 10
release groups and top 10 recordings (2001 API calls total)
- Dedicated 3 req/s rate limiter for indexer (LB allows 30/10s)
- Bounded concurrency (3 goroutines) with progress logging
- Batch INSERTs in transactions of 100 rows
- FTS5 query with prefix matching ('for you' → 'for* you*')
- Results sorted by popularity descending
- Skips rebuild if index is < 7 days old
- Marks index ready from existing rows if build fails
- Context cancellation for clean shutdown
This commit is contained in:
@@ -29,6 +29,15 @@ func NewRateLimiter() *RateLimiter {
|
||||
}
|
||||
}
|
||||
|
||||
// NewRateLimiterN returns a rate limiter that allows n requests
|
||||
// per second with a burst of n. Used for background tasks like
|
||||
// index building where a higher rate is acceptable.
|
||||
func NewRateLimiterN(n int) *RateLimiter {
|
||||
return &RateLimiter{
|
||||
limiter: rate.NewLimiter(rate.Limit(n), n),
|
||||
}
|
||||
}
|
||||
|
||||
// Wait blocks until the rate limiter allows the caller to proceed
|
||||
// or the context is cancelled. Returns ctx.Err() if the context
|
||||
// expires before a token becomes available.
|
||||
|
||||
Reference in New Issue
Block a user