mirror of
https://git.sr.ht/~phw/scotty
synced 2025-07-02 00:01:56 +02:00
Introduced Backend.Close method
This allows Backend implementations to free used resources. Currently used for musicbrainzws2.Client
This commit is contained in:
parent
c1a480a1a6
commit
499786cab9
14 changed files with 45 additions and 8 deletions
|
@ -36,12 +36,18 @@ const lovesBatchSize = listenbrainz.MaxItemsPerGet
|
|||
|
||||
type ListenBrainzApiBackend struct {
|
||||
client listenbrainz.Client
|
||||
mbClient musicbrainzws2.Client
|
||||
mbClient *musicbrainzws2.Client
|
||||
username string
|
||||
checkDuplicates bool
|
||||
existingMBIDs map[mbtypes.MBID]bool
|
||||
}
|
||||
|
||||
func (b *ListenBrainzApiBackend) Close() {
|
||||
if b.mbClient != nil {
|
||||
b.mbClient.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func (b *ListenBrainzApiBackend) Name() string { return "listenbrainz" }
|
||||
|
||||
func (b *ListenBrainzApiBackend) Options() []models.BackendOption {
|
||||
|
@ -62,7 +68,7 @@ func (b *ListenBrainzApiBackend) Options() []models.BackendOption {
|
|||
|
||||
func (b *ListenBrainzApiBackend) InitConfig(config *config.ServiceConfig) error {
|
||||
b.client = listenbrainz.NewClient(config.GetString("token"), version.UserAgent())
|
||||
b.mbClient = *musicbrainzws2.NewClient(musicbrainzws2.AppInfo{
|
||||
b.mbClient = musicbrainzws2.NewClient(musicbrainzws2.AppInfo{
|
||||
Name: version.AppName,
|
||||
Version: version.AppVersion,
|
||||
URL: version.AppURL,
|
||||
|
@ -261,7 +267,7 @@ out:
|
|||
// Missing track metadata indicates that the recording MBID is no
|
||||
// longer available and might have been merged. Try fetching details
|
||||
// from MusicBrainz.
|
||||
lovesBatch, err := ExtendTrackMetadata(ctx, &b.client, &b.mbClient, &batch)
|
||||
lovesBatch, err := ExtendTrackMetadata(ctx, &b.client, b.mbClient, &batch)
|
||||
if err != nil {
|
||||
results <- models.LovesResult{Error: err}
|
||||
return
|
||||
|
@ -276,7 +282,7 @@ out:
|
|||
offset += listenbrainz.MaxItemsPerGet
|
||||
}
|
||||
|
||||
lovesBatch, err := ExtendTrackMetadata(ctx, &b.client, &b.mbClient, &batch)
|
||||
lovesBatch, err := ExtendTrackMetadata(ctx, &b.client, b.mbClient, &batch)
|
||||
if err != nil {
|
||||
results <- models.LovesResult{Error: err}
|
||||
return
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue