feat: implement rate limiting and caching layer for MusicBrainz provider

- Add golang.org/x/time/rate dependency for token-bucket rate limiting
- Replace custom channel-based rate limiter with rate.NewLimiter(1, 1)
- Add context.Context support to doGet for cancellation
- Add cached_at column to external_releases via migration 005
- Implement cache hit/miss queries with TTL-based filtering
- Add CacheStats type for tracking cached RGIDs
- Update ExternalRelease struct with CachedAt field
- Add rate limiting tests (1 req/sec enforcement, burst behavior)
- Add cache tests (hit, miss, expired, mixed, empty artist)
- Update migration count test for new migration
This commit is contained in:
2026-05-26 12:15:28 +03:00
parent 674daed93b
commit b0f69d3a4f
10 changed files with 518 additions and 119 deletions

View File

@@ -56,13 +56,13 @@ Implement a MusicBrainz API provider with strict 1 request/second rate limiting,
- [x] run tests - must pass before next task
### Task 2: Implement rate limiting and caching layer
- [ ] add golang.org/x/time/rate dependency to go.mod
- [ ] implement rate limiter using golang.org/x/time/rate.NewLimiter(1, 1) for 1 req/sec
- [ ] create wrapper method for rate-limited HTTP GET requests
- [ ] implement caching check: query database for existing Release Group data within TTL
- [ ] write tests for rate limiting behavior (timing tests)
- [ ] write tests for cache hit/miss logic
- [ ] run tests - must pass before next task
- [x] add golang.org/x/time/rate dependency to go.mod
- [x] implement rate limiter using golang.org/x/time/rate.NewLimiter(1, 1) for 1 req/sec
- [x] create wrapper method for rate-limited HTTP GET requests
- [x] implement caching check: query database for existing Release Group data within TTL
- [x] write tests for rate limiting behavior (timing tests)
- [x] write tests for cache hit/miss logic
- [x] run tests - must pass before next task
### Task 3: Implement MusicBrainz API endpoints and filtering
- [ ] implement GetArtistReleaseGroups(artistMBID string) method