mirror of
https://git.sr.ht/~phw/scotty
synced 2025-06-01 19:38:34 +02:00
Fixed import log output duplicating
This commit is contained in:
parent
b1b0df7763
commit
312d9860cf
4 changed files with 39 additions and 9 deletions
|
@ -17,6 +17,7 @@
|
||||||
- deezer: fixed endless export loop if the user's listen history was empty.
|
- deezer: fixed endless export loop if the user's listen history was empty.
|
||||||
- dump: it is now possible to specify a file to write the text output to.
|
- dump: it is now possible to specify a file to write the text output to.
|
||||||
- Fixed potential issues with MusicBrainz rate limiting.
|
- Fixed potential issues with MusicBrainz rate limiting.
|
||||||
|
- Fixed import log output duplicating.
|
||||||
|
|
||||||
|
|
||||||
## 0.6.0 - 2025-05-23
|
## 0.6.0 - 2025-05-23
|
||||||
|
|
|
@ -112,8 +112,9 @@ func process[R models.LovesResult | models.ListensResult, P ImportProcessor[R]](
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
importResult, err := processor.Import(ctx, exportResult, result, out, progress)
|
importResult, err := processor.Import(
|
||||||
result.Update(importResult)
|
ctx, exportResult, result.Copy(), out, progress)
|
||||||
|
result.Update(&importResult)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
processor.ImportBackend().FinishImport()
|
processor.ImportBackend().FinishImport()
|
||||||
out <- handleError(result, err, progress)
|
out <- handleError(result, err, progress)
|
||||||
|
|
|
@ -196,11 +196,21 @@ func (i *ImportResult) UpdateTimestamp(newTime time.Time) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *ImportResult) Update(from ImportResult) {
|
func (i *ImportResult) Update(from *ImportResult) {
|
||||||
i.TotalCount = from.TotalCount
|
if i != from {
|
||||||
i.ImportCount = from.ImportCount
|
i.TotalCount = from.TotalCount
|
||||||
i.UpdateTimestamp(from.LastTimestamp)
|
i.ImportCount = from.ImportCount
|
||||||
i.ImportLog = append(i.ImportLog, from.ImportLog...)
|
i.UpdateTimestamp(from.LastTimestamp)
|
||||||
|
i.ImportLog = append(i.ImportLog, from.ImportLog...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *ImportResult) Copy() ImportResult {
|
||||||
|
return ImportResult{
|
||||||
|
TotalCount: i.TotalCount,
|
||||||
|
ImportCount: i.ImportCount,
|
||||||
|
LastTimestamp: i.LastTimestamp,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *ImportResult) Log(t LogEntryType, msg string) {
|
func (i *ImportResult) Log(t LogEntryType, msg string) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
Copyright © 2023 Philipp Wolfer <phw@uploadedlobster.com>
|
Copyright © 2023-2025 Philipp Wolfer <phw@uploadedlobster.com>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
@ -138,13 +138,31 @@ func TestImportResultUpdate(t *testing.T) {
|
||||||
LastTimestamp: time.Now().Add(1 * time.Hour),
|
LastTimestamp: time.Now().Add(1 * time.Hour),
|
||||||
ImportLog: []models.LogEntry{logEntry2},
|
ImportLog: []models.LogEntry{logEntry2},
|
||||||
}
|
}
|
||||||
result.Update(newResult)
|
result.Update(&newResult)
|
||||||
assert.Equal(t, 120, result.TotalCount)
|
assert.Equal(t, 120, result.TotalCount)
|
||||||
assert.Equal(t, 50, result.ImportCount)
|
assert.Equal(t, 50, result.ImportCount)
|
||||||
assert.Equal(t, newResult.LastTimestamp, result.LastTimestamp)
|
assert.Equal(t, newResult.LastTimestamp, result.LastTimestamp)
|
||||||
assert.Equal(t, []models.LogEntry{logEntry1, logEntry2}, result.ImportLog)
|
assert.Equal(t, []models.LogEntry{logEntry1, logEntry2}, result.ImportLog)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestImportResultCopy(t *testing.T) {
|
||||||
|
logEntry := models.LogEntry{
|
||||||
|
Type: models.Warning,
|
||||||
|
Message: "foo",
|
||||||
|
}
|
||||||
|
result := models.ImportResult{
|
||||||
|
TotalCount: 100,
|
||||||
|
ImportCount: 20,
|
||||||
|
LastTimestamp: time.Now(),
|
||||||
|
ImportLog: []models.LogEntry{logEntry},
|
||||||
|
}
|
||||||
|
copy := result.Copy()
|
||||||
|
assert.Equal(t, result.TotalCount, copy.TotalCount)
|
||||||
|
assert.Equal(t, result.ImportCount, copy.ImportCount)
|
||||||
|
assert.Equal(t, result.LastTimestamp, copy.LastTimestamp)
|
||||||
|
assert.Empty(t, copy.ImportLog)
|
||||||
|
}
|
||||||
|
|
||||||
func TestImportResultLog(t *testing.T) {
|
func TestImportResultLog(t *testing.T) {
|
||||||
result := models.ImportResult{}
|
result := models.ImportResult{}
|
||||||
result.Log(models.Warning, "foo")
|
result.Log(models.Warning, "foo")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue