Implemented progressbar for export/import

This commit is contained in:
Philipp Wolfer 2023-11-16 00:45:00 +01:00
parent ab04eb1123
commit 6e330daf06
No known key found for this signature in database
GPG key ID: 8FDF744D4919943B
24 changed files with 590 additions and 239 deletions

View file

@ -105,13 +105,14 @@ func (l LovesList) Swap(i, j int) {
}
type ListensResult struct {
Error error
Listens ListensList
Listens ListensList
OldestTimestamp time.Time
Error error
}
type LovesResult struct {
Error error
Loves LovesList
Error error
}
type ImportResult struct {
@ -119,6 +120,9 @@ type ImportResult struct {
ImportCount int
LastTimestamp time.Time
ImportErrors []string
// Error is only set if an unrecoverable import error occurred
Error error
}
// Sets LastTimestamp to newTime, if newTime is newer than LastTimestamp
@ -127,3 +131,27 @@ func (i *ImportResult) UpdateTimestamp(newTime time.Time) {
i.LastTimestamp = newTime
}
}
func (i *ImportResult) Update(from ImportResult) {
i.TotalCount = from.TotalCount
i.ImportCount += from.ImportCount
i.UpdateTimestamp(from.LastTimestamp)
}
type Progress struct {
Total int64
Elapsed int64
Completed bool
}
func (p Progress) FromImportResult(result ImportResult) Progress {
p.Total = int64(result.TotalCount)
p.Elapsed = int64(result.ImportCount)
return p
}
func (p Progress) Complete() Progress {
p.Total = p.Elapsed
p.Completed = true
return p
}