fix(GODT-2828): Fix negative report time

This commit is contained in:
Leander Beernaert
2023-08-31 13:37:43 +02:00
parent a189c35899
commit 970de4c205

View File

@ -58,6 +58,7 @@ func (rep *syncReporter) OnProgress(ctx context.Context, delta int64) {
rep.count += delta rep.count += delta
var progress float64 var progress float64
var remaining time.Duration
// It's possible for count to be bigger or smaller than total depending on when the sync begins and whether new // It's possible for count to be bigger or smaller than total depending on when the sync begins and whether new
// messages are added/removed during this period. When this happens just limited the progress to 100%. // messages are added/removed during this period. When this happens just limited the progress to 100%.
@ -65,6 +66,7 @@ func (rep *syncReporter) OnProgress(ctx context.Context, delta int64) {
progress = 1 progress = 1
} else { } else {
progress = float64(rep.count) / float64(rep.total) progress = float64(rep.count) / float64(rep.total)
remaining = time.Since(rep.start) * time.Duration(rep.total-(rep.count+1)) / time.Duration(rep.count+1)
} }
if time.Since(rep.last) > rep.freq { if time.Since(rep.last) > rep.freq {
@ -72,7 +74,7 @@ func (rep *syncReporter) OnProgress(ctx context.Context, delta int64) {
UserID: rep.userID, UserID: rep.userID,
Progress: progress, Progress: progress,
Elapsed: time.Since(rep.start), Elapsed: time.Since(rep.start),
Remaining: time.Since(rep.start) * time.Duration(rep.total-(rep.count+1)) / time.Duration(rep.count+1), Remaining: remaining,
}) })
rep.last = time.Now() rep.last = time.Now()