From 763c8208f778d212d6599eb9d6b245f4587cbf75 Mon Sep 17 00:00:00 2001 From: David Dworken Date: Wed, 13 Sep 2023 19:20:15 -0700 Subject: [PATCH] Make RetryingDbFunction more lenient so that it always ignores UNIQUE constraint errors, since if a DB.Create returns a UNIQUE error, then the create is not actually necessary --- client/lib/lib.go | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/client/lib/lib.go b/client/lib/lib.go index a4e8220..2a2f48a 100644 --- a/client/lib/lib.go +++ b/client/lib/lib.go @@ -148,7 +148,7 @@ func buildTableRow(ctx context.Context, columnNames []string, entry data.History case "Timestamp": row = append(row, entry.StartTime.Local().Format(hctx.GetConf(ctx).TimestampFormat)) case "Runtime": - if entry.EndTime == time.Unix(0, 0) { + if entry.EndTime.UnixMilli() == 0 { // An EndTime of zero means this is a pre-saved entry that never finished row = append(row, "N/A") } else { @@ -718,12 +718,8 @@ func RetryingDbFunction(dbFunc func() error) error { time.Sleep(time.Duration(i*rand.Intn(100)) * time.Millisecond) continue } - if strings.Contains(errMsg, "UNIQUE constraint failed") { - if i == 0 { - return err - } else { - return nil - } + if strings.Contains(errMsg, "UNIQUE constraint failed: history_entries.") { + return nil } return fmt.Errorf("unrecoverable sqlite error: %w", err) }