Something + add comments to proto

This commit is contained in:
Alexander
2026-07-12 10:16:54 +02:00
parent fde1b4cd3e
commit 995397e495
12 changed files with 440 additions and 243 deletions
+41 -10
View File
@@ -17,8 +17,10 @@ import (
)
const (
baseURL = "https://musicbrainz.org/ws/2"
userAgent = "MetadataAggregator/0.1.0 (https://github.com/metadata-agregator)"
baseURL = "https://musicbrainz.org/ws/2"
userAgent = "MetadataAggregator/0.1.0 (https://github.com/metadata-agregator)"
maxRetries = 3
baseBackoff = 2 * time.Second
)
type client struct {
@@ -36,16 +38,45 @@ func newClient() *client {
}
func (c *client) get(ctx context.Context, endpoint string, params url.Values) ([]byte, error) {
if err := c.waitForRateLimit(ctx); err != nil {
return nil, err
var lastErr error
for attempt := 0; attempt <= maxRetries; attempt++ {
if err := c.waitForRateLimit(ctx); err != nil {
return nil, err
}
req, err := c.buildRequest(ctx, endpoint, params)
if err != nil {
return nil, err
}
data, err := c.executeAndRead(ctx, req, endpoint)
if err == nil {
return data, nil
}
if err != ErrRateLimited {
return nil, err
}
lastErr = err
if attempt < maxRetries {
backoff := baseBackoff * time.Duration(1<<attempt)
zerolog.Ctx(ctx).Info().
Int("attempt", attempt+1).
Int("max_retries", maxRetries).
Dur("backoff", backoff).
Msg("rate limited, waiting before retry")
select {
case <-ctx.Done():
return nil, ctx.Err()
case <-time.After(backoff):
}
}
}
req, err := c.buildRequest(ctx, endpoint, params)
if err != nil {
return nil, err
}
return c.executeAndRead(ctx, req, endpoint)
return nil, lastErr
}
func (c *client) waitForRateLimit(ctx context.Context) error {
+1 -1
View File
@@ -128,7 +128,7 @@ func (s *MetadataService) deduplicateArtists(dbResult, mbResult *domain.SearchRe
total := 0
addArtist := func(artist domain.Artist) {
if artist.Type == "Other" {
if artist.Type == "" || artist.Type == "Other" {
return
}
for _, ext := range artist.ExternalIDs {