Fixed import log output duplicating

This commit is contained in:
Philipp Wolfer 2025-05-24 20:43:02 +02:00
parent b1b0df7763
commit 312d9860cf
No known key found for this signature in database
GPG key ID: 8FDF744D4919943B
4 changed files with 39 additions and 9 deletions

View file

@ -17,6 +17,7 @@
- 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.
- Fixed potential issues with MusicBrainz rate limiting.
- Fixed import log output duplicating.
## 0.6.0 - 2025-05-23

View file

@ -112,8 +112,9 @@ func process[R models.LovesResult | models.ListensResult, P ImportProcessor[R]](
return
}
importResult, err := processor.Import(ctx, exportResult, result, out, progress)
result.Update(importResult)
importResult, err := processor.Import(
ctx, exportResult, result.Copy(), out, progress)
result.Update(&importResult)
if err != nil {
processor.ImportBackend().FinishImport()
out <- handleError(result, err, progress)

View file

@ -196,11 +196,21 @@ func (i *ImportResult) UpdateTimestamp(newTime time.Time) {
}
}
func (i *ImportResult) Update(from ImportResult) {
i.TotalCount = from.TotalCount
i.ImportCount = from.ImportCount
i.UpdateTimestamp(from.LastTimestamp)
i.ImportLog = append(i.ImportLog, from.ImportLog...)
func (i *ImportResult) Update(from *ImportResult) {
if i != from {
i.TotalCount = from.TotalCount
i.ImportCount = from.ImportCount
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) {

View file

@ -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
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),
ImportLog: []models.LogEntry{logEntry2},
}
result.Update(newResult)
result.Update(&newResult)
assert.Equal(t, 120, result.TotalCount)
assert.Equal(t, 50, result.ImportCount)
assert.Equal(t, newResult.LastTimestamp, result.LastTimestamp)
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) {
result := models.ImportResult{}
result.Log(models.Warning, "foo")