listenbrainz: fetch listens in reverse listen time order

This allows parallel import
This commit is contained in:
Philipp Wolfer 2023-11-28 17:45:53 +01:00
parent cde9b28c28
commit 4bf0f2c81d
No known key found for this signature in database
GPG key ID: 8FDF744D4919943B
6 changed files with 34 additions and 20 deletions

View file

@ -122,15 +122,14 @@ func (b *SpotifyApiBackend) ExportListens(oldestTimestamp time.Time, results cha
break
}
listens := make(models.ListensList, 0, len(result.Items))
listens := make(models.ListensList, 0, count)
for _, listen := range result.Items {
l := listen.AsListen()
if l.ListenedAt.Unix() > oldestTimestamp.Unix() {
listens = append(listens, l)
} else {
// result contains listens older then oldestTimestamp,
// we can stop requesting more
// result contains listens older then oldestTimestamp
break
}
}