mirror of
https://github.com/gabehf/Koito.git
synced 2026-03-07 13:38:15 -08:00
feat: configurable mbz rate limit
This commit is contained in:
parent
d2277aea32
commit
7b18ebb294
2 changed files with 13 additions and 1 deletions
|
|
@ -23,6 +23,7 @@ const (
|
|||
ENABLE_FULL_IMAGE_CACHE_ENV = "KOITO_ENABLE_FULL_IMAGE_CACHE"
|
||||
LOG_LEVEL_ENV = "KOITO_LOG_LEVEL"
|
||||
MUSICBRAINZ_URL_ENV = "KOITO_MUSICBRAINZ_URL"
|
||||
MUSICBRAINZ_RATE_LIMIT_ENV = "KOITO_MUSICBRAINZ_RATE_LIMIT"
|
||||
ENABLE_LBZ_RELAY_ENV = "KOITO_ENABLE_LBZ_RELAY"
|
||||
LBZ_RELAY_URL_ENV = "KOITO_LBZ_RELAY_URL"
|
||||
LBZ_RELAY_TOKEN_ENV = "KOITO_LBZ_RELAY_TOKEN"
|
||||
|
|
@ -45,6 +46,7 @@ type config struct {
|
|||
// baseUrl string
|
||||
databaseUrl string
|
||||
musicBrainzUrl string
|
||||
musicBrainzRateLimit int
|
||||
logLevel int
|
||||
structuredLogging bool
|
||||
enableFullImageCache bool
|
||||
|
|
@ -95,6 +97,10 @@ func loadConfig(getenv func(string) string) (*config, error) {
|
|||
if err != nil {
|
||||
cfg.listenPort = defaultListenPort
|
||||
}
|
||||
cfg.musicBrainzRateLimit, err = strconv.Atoi(getenv(MUSICBRAINZ_RATE_LIMIT_ENV))
|
||||
if err != nil {
|
||||
cfg.musicBrainzRateLimit = 1
|
||||
}
|
||||
cfg.musicBrainzUrl = getenv(MUSICBRAINZ_URL_ENV)
|
||||
if cfg.musicBrainzUrl == "" {
|
||||
cfg.musicBrainzUrl = defaultMusicBrainzUrl
|
||||
|
|
@ -192,6 +198,12 @@ func MusicBrainzUrl() string {
|
|||
return globalConfig.musicBrainzUrl
|
||||
}
|
||||
|
||||
func MusicBrainzRateLimit() int {
|
||||
lock.RLock()
|
||||
defer lock.RUnlock()
|
||||
return globalConfig.musicBrainzRateLimit
|
||||
}
|
||||
|
||||
func LogLevel() int {
|
||||
lock.RLock()
|
||||
defer lock.RUnlock()
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ func NewMusicBrainzClient() *MusicBrainzClient {
|
|||
ret := new(MusicBrainzClient)
|
||||
ret.url = cfg.MusicBrainzUrl()
|
||||
ret.userAgent = "Koito/0.0.1 (contact@koito.app)"
|
||||
ret.requestQueue = queue.NewRequestQueue(1, 1)
|
||||
ret.requestQueue = queue.NewRequestQueue(cfg.MusicBrainzRateLimit(), cfg.MusicBrainzRateLimit())
|
||||
return ret
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue