ListenBrainz: Fix loves import loading all existing loves

Fixes import if the user had more than 1000 loves already
This commit is contained in:
Philipp Wolfer 2025-04-27 16:55:14 +02:00
parent 01e7569051
commit da6c920789
No known key found for this signature in database
GPG key ID: 8FDF744D4919943B

View file

@ -233,17 +233,20 @@ func (b *ListenBrainzApiBackend) ImportLoves(export models.LovesResult, importRe
if len(b.existingMBIDs) == 0 { if len(b.existingMBIDs) == 0 {
existingLovesChan := make(chan models.LovesResult) existingLovesChan := make(chan models.LovesResult)
go b.ExportLoves(time.Unix(0, 0), existingLovesChan, progress) go b.ExportLoves(time.Unix(0, 0), existingLovesChan, progress)
existingLoves := <-existingLovesChan
// TODO: Store MBIDs directly
b.existingMBIDs = make(map[mbtypes.MBID]bool, MaxItemsPerGet)
for existingLoves := range existingLovesChan {
if existingLoves.Error != nil { if existingLoves.Error != nil {
return importResult, existingLoves.Error return importResult, existingLoves.Error
} }
// TODO: Store MBIDs directly
b.existingMBIDs = make(map[mbtypes.MBID]bool, len(existingLoves.Items))
for _, love := range existingLoves.Items { for _, love := range existingLoves.Items {
b.existingMBIDs[love.RecordingMBID] = true b.existingMBIDs[love.RecordingMBID] = true
} }
} }
}
for _, love := range export.Items { for _, love := range export.Items {
recordingMBID := love.RecordingMBID recordingMBID := love.RecordingMBID
@ -268,6 +271,8 @@ func (b *ListenBrainzApiBackend) ImportLoves(export models.LovesResult, importRe
ok = err == nil && resp.Status == "ok" ok = err == nil && resp.Status == "ok"
if err != nil { if err != nil {
errMsg = err.Error() errMsg = err.Error()
} else {
b.existingMBIDs[recordingMBID] = true
} }
} }