mirror of
https://git.sr.ht/~phw/scotty
synced 2025-04-16 01:59:29 +02:00
Avoid double closing of export progress channel
This commit is contained in:
parent
e8fdfb95a6
commit
fb285930c0
9 changed files with 2 additions and 11 deletions
|
@ -71,7 +71,6 @@ func (b *DeezerApiBackend) ExportListens(oldestTimestamp time.Time, results chan
|
||||||
perPage := MaxItemsPerGet
|
perPage := MaxItemsPerGet
|
||||||
|
|
||||||
defer close(results)
|
defer close(results)
|
||||||
defer close(progress)
|
|
||||||
|
|
||||||
p := models.Progress{Total: int64(perPage)}
|
p := models.Progress{Total: int64(perPage)}
|
||||||
var totalCount int
|
var totalCount int
|
||||||
|
@ -139,7 +138,6 @@ func (b *DeezerApiBackend) ExportLoves(oldestTimestamp time.Time, results chan m
|
||||||
perPage := MaxItemsPerGet
|
perPage := MaxItemsPerGet
|
||||||
|
|
||||||
defer close(results)
|
defer close(results)
|
||||||
defer close(progress)
|
|
||||||
|
|
||||||
p := models.Progress{Total: int64(perPage)}
|
p := models.Progress{Total: int64(perPage)}
|
||||||
var totalCount int
|
var totalCount int
|
||||||
|
|
|
@ -47,7 +47,6 @@ func (b *FunkwhaleApiBackend) ExportListens(oldestTimestamp time.Time, results c
|
||||||
perPage := MaxItemsPerGet
|
perPage := MaxItemsPerGet
|
||||||
|
|
||||||
defer close(results)
|
defer close(results)
|
||||||
defer close(progress)
|
|
||||||
|
|
||||||
// We need to gather the full list of listens in order to sort them
|
// We need to gather the full list of listens in order to sort them
|
||||||
listens := make(models.ListensList, 0, 2*perPage)
|
listens := make(models.ListensList, 0, 2*perPage)
|
||||||
|
@ -97,7 +96,6 @@ func (b *FunkwhaleApiBackend) ExportLoves(oldestTimestamp time.Time, results cha
|
||||||
perPage := MaxItemsPerGet
|
perPage := MaxItemsPerGet
|
||||||
|
|
||||||
defer close(results)
|
defer close(results)
|
||||||
defer close(progress)
|
|
||||||
|
|
||||||
// We need to gather the full list of listens in order to sort them
|
// We need to gather the full list of listens in order to sort them
|
||||||
loves := make(models.LovesList, 0, 2*perPage)
|
loves := make(models.LovesList, 0, 2*perPage)
|
||||||
|
|
|
@ -51,7 +51,6 @@ func (b *ListenBrainzApiBackend) ExportListens(oldestTimestamp time.Time, result
|
||||||
totalDuration := startTime.Sub(oldestTimestamp)
|
totalDuration := startTime.Sub(oldestTimestamp)
|
||||||
|
|
||||||
defer close(results)
|
defer close(results)
|
||||||
defer close(progress)
|
|
||||||
|
|
||||||
// FIXME: Optimize by fetching the listens in reverse listen time order
|
// FIXME: Optimize by fetching the listens in reverse listen time order
|
||||||
listens := make(models.ListensList, 0, 2*MaxItemsPerGet)
|
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) {
|
func (b *ListenBrainzApiBackend) ExportLoves(oldestTimestamp time.Time, results chan models.LovesResult, progress chan models.Progress) {
|
||||||
offset := 0
|
offset := 0
|
||||||
defer close(results)
|
defer close(results)
|
||||||
defer close(progress)
|
|
||||||
loves := make(models.LovesList, 0, 2*MaxItemsPerGet)
|
loves := make(models.LovesList, 0, 2*MaxItemsPerGet)
|
||||||
p := models.Progress{}
|
p := models.Progress{}
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,6 @@ func (b *MalojaApiBackend) ExportListens(oldestTimestamp time.Time, results chan
|
||||||
perPage := MaxItemsPerGet
|
perPage := MaxItemsPerGet
|
||||||
|
|
||||||
defer close(results)
|
defer close(results)
|
||||||
defer close(progress)
|
|
||||||
|
|
||||||
// We need to gather the full list of listens in order to sort them
|
// We need to gather the full list of listens in order to sort them
|
||||||
listens := make(models.ListensList, 0, 2*perPage)
|
listens := make(models.ListensList, 0, 2*perPage)
|
||||||
|
|
|
@ -100,7 +100,6 @@ func (b *ScrobblerLogBackend) FinishImport() error {
|
||||||
|
|
||||||
func (b *ScrobblerLogBackend) ExportListens(oldestTimestamp time.Time, results chan models.ListensResult, progress chan models.Progress) {
|
func (b *ScrobblerLogBackend) ExportListens(oldestTimestamp time.Time, results chan models.ListensResult, progress chan models.Progress) {
|
||||||
defer close(results)
|
defer close(results)
|
||||||
defer close(progress)
|
|
||||||
file, err := os.Open(b.filePath)
|
file, err := os.Open(b.filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
progress <- models.Progress{}.Complete()
|
progress <- models.Progress{}.Complete()
|
||||||
|
|
|
@ -89,7 +89,6 @@ func (b *SpotifyApiBackend) ExportListens(oldestTimestamp time.Time, results cha
|
||||||
totalDuration := startTime.Sub(oldestTimestamp)
|
totalDuration := startTime.Sub(oldestTimestamp)
|
||||||
|
|
||||||
defer close(results)
|
defer close(results)
|
||||||
defer close(progress)
|
|
||||||
|
|
||||||
p := models.Progress{Total: int64(totalDuration.Seconds())}
|
p := models.Progress{Total: int64(totalDuration.Seconds())}
|
||||||
|
|
||||||
|
@ -153,7 +152,6 @@ func (b *SpotifyApiBackend) ExportLoves(oldestTimestamp time.Time, results chan
|
||||||
perPage := MaxItemsPerGet
|
perPage := MaxItemsPerGet
|
||||||
|
|
||||||
defer close(results)
|
defer close(results)
|
||||||
defer close(progress)
|
|
||||||
|
|
||||||
p := models.Progress{Total: int64(perPage)}
|
p := models.Progress{Total: int64(perPage)}
|
||||||
var totalCount int
|
var totalCount int
|
||||||
|
|
|
@ -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) {
|
func (b *SubsonicApiBackend) ExportLoves(oldestTimestamp time.Time, results chan models.LovesResult, progress chan models.Progress) {
|
||||||
defer close(results)
|
defer close(results)
|
||||||
defer close(progress)
|
|
||||||
err := b.client.Authenticate(b.password)
|
err := b.client.Authenticate(b.password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
progress <- models.Progress{}.Complete()
|
progress <- models.Progress{}.Complete()
|
||||||
|
|
|
@ -77,6 +77,7 @@ var listensCmd = &cobra.Command{
|
||||||
resultChan := make(chan models.ImportResult)
|
resultChan := make(chan models.ImportResult)
|
||||||
go backends.ProcessListensImports(importBackend, listensChan, resultChan, importProgress)
|
go backends.ProcessListensImports(importBackend, listensChan, resultChan, importProgress)
|
||||||
result := <-resultChan
|
result := <-resultChan
|
||||||
|
close(exportProgress)
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
progress.Wait()
|
progress.Wait()
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
|
|
|
@ -77,6 +77,7 @@ var lovesCmd = &cobra.Command{
|
||||||
resultChan := make(chan models.ImportResult)
|
resultChan := make(chan models.ImportResult)
|
||||||
go backends.ProcessLovesImports(importBackend, lovesChan, resultChan, importProgress)
|
go backends.ProcessLovesImports(importBackend, lovesChan, resultChan, importProgress)
|
||||||
result := <-resultChan
|
result := <-resultChan
|
||||||
|
close(exportProgress)
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
progress.Wait()
|
progress.Wait()
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
|
|
Loading…
Add table
Reference in a new issue