Avoid double closing of export progress channel

This commit is contained in:
Philipp Wolfer 2023-11-23 22:45:31 +01:00
parent e8fdfb95a6
commit fb285930c0
No known key found for this signature in database
GPG key ID: 8FDF744D4919943B
9 changed files with 2 additions and 11 deletions

View file

@ -71,7 +71,6 @@ func (b *DeezerApiBackend) ExportListens(oldestTimestamp time.Time, results chan
perPage := MaxItemsPerGet
defer close(results)
defer close(progress)
p := models.Progress{Total: int64(perPage)}
var totalCount int
@ -139,7 +138,6 @@ func (b *DeezerApiBackend) ExportLoves(oldestTimestamp time.Time, results chan m
perPage := MaxItemsPerGet
defer close(results)
defer close(progress)
p := models.Progress{Total: int64(perPage)}
var totalCount int

View file

@ -47,7 +47,6 @@ func (b *FunkwhaleApiBackend) ExportListens(oldestTimestamp time.Time, results c
perPage := MaxItemsPerGet
defer close(results)
defer close(progress)
// We need to gather the full list of listens in order to sort them
listens := make(models.ListensList, 0, 2*perPage)
@ -97,7 +96,6 @@ func (b *FunkwhaleApiBackend) ExportLoves(oldestTimestamp time.Time, results cha
perPage := MaxItemsPerGet
defer close(results)
defer close(progress)
// We need to gather the full list of listens in order to sort them
loves := make(models.LovesList, 0, 2*perPage)

View file

@ -51,7 +51,6 @@ func (b *ListenBrainzApiBackend) ExportListens(oldestTimestamp time.Time, result
totalDuration := startTime.Sub(oldestTimestamp)
defer close(results)
defer close(progress)
// FIXME: Optimize by fetching the listens in reverse listen time order
listens := make(models.ListensList, 0, 2*MaxItemsPerGet)
@ -140,7 +139,6 @@ func (b *ListenBrainzApiBackend) ImportListens(export models.ListensResult, impo
func (b *ListenBrainzApiBackend) ExportLoves(oldestTimestamp time.Time, results chan models.LovesResult, progress chan models.Progress) {
offset := 0
defer close(results)
defer close(progress)
loves := make(models.LovesList, 0, 2*MaxItemsPerGet)
p := models.Progress{}

View file

@ -50,7 +50,6 @@ func (b *MalojaApiBackend) ExportListens(oldestTimestamp time.Time, results chan
perPage := MaxItemsPerGet
defer close(results)
defer close(progress)
// We need to gather the full list of listens in order to sort them
listens := make(models.ListensList, 0, 2*perPage)

View file

@ -100,7 +100,6 @@ func (b *ScrobblerLogBackend) FinishImport() error {
func (b *ScrobblerLogBackend) ExportListens(oldestTimestamp time.Time, results chan models.ListensResult, progress chan models.Progress) {
defer close(results)
defer close(progress)
file, err := os.Open(b.filePath)
if err != nil {
progress <- models.Progress{}.Complete()

View file

@ -89,7 +89,6 @@ func (b *SpotifyApiBackend) ExportListens(oldestTimestamp time.Time, results cha
totalDuration := startTime.Sub(oldestTimestamp)
defer close(results)
defer close(progress)
p := models.Progress{Total: int64(totalDuration.Seconds())}
@ -153,7 +152,6 @@ func (b *SpotifyApiBackend) ExportLoves(oldestTimestamp time.Time, results chan
perPage := MaxItemsPerGet
defer close(results)
defer close(progress)
p := models.Progress{Total: int64(perPage)}
var totalCount int

View file

@ -46,7 +46,6 @@ func (b *SubsonicApiBackend) FromConfig(config *viper.Viper) models.Backend {
func (b *SubsonicApiBackend) ExportLoves(oldestTimestamp time.Time, results chan models.LovesResult, progress chan models.Progress) {
defer close(results)
defer close(progress)
err := b.client.Authenticate(b.password)
if err != nil {
progress <- models.Progress{}.Complete()

View file

@ -77,6 +77,7 @@ var listensCmd = &cobra.Command{
resultChan := make(chan models.ImportResult)
go backends.ProcessListensImports(importBackend, listensChan, resultChan, importProgress)
result := <-resultChan
close(exportProgress)
wg.Wait()
progress.Wait()
if result.Error != nil {

View file

@ -77,6 +77,7 @@ var lovesCmd = &cobra.Command{
resultChan := make(chan models.ImportResult)
go backends.ProcessLovesImports(importBackend, lovesChan, resultChan, importProgress)
result := <-resultChan
close(exportProgress)
wg.Wait()
progress.Wait()
if result.Error != nil {