From 5832e8346091f87b7d5f9f472f89deed484c4d59 Mon Sep 17 00:00:00 2001 From: dragonmuffin Date: Sat, 17 Aug 2024 18:41:37 +0500 Subject: [PATCH] fix: improve rejudge --- internal/models/result.go | 11 ++++++----- internal/storage/solution.go | 14 +++++++++----- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/internal/models/result.go b/internal/models/result.go index c608d78..75b4cff 100644 --- a/internal/models/result.go +++ b/internal/models/result.go @@ -6,11 +6,12 @@ type Result int32 const ( NotTested Result = 0 - Accepted Result = 1 - TimeLimitExceeded Result = 2 - MemoryLimitExceeded Result = 3 - CompilationError Result = 4 - SystemFailDuringTesting Result = 5 + Testing Result = 1 + Accepted Result = 2 + TimeLimitExceeded Result = 3 + MemoryLimitExceeded Result = 4 + CompilationError Result = 5 + SystemFailDuringTesting Result = 6 ) func (result Result) Valid() error { diff --git a/internal/storage/solution.go b/internal/storage/solution.go index 522feef..2f03558 100644 --- a/internal/storage/solution.go +++ b/internal/storage/solution.go @@ -70,14 +70,18 @@ func (storage *SolutionStorage) ReadSolutionById(ctx context.Context, id int32) } func (storage *SolutionStorage) RejudgeSolution(ctx context.Context, id int32) error { - query := storage.db.Rebind("UPDATE solutions SET result = ? WHERE id = ?") - _, err := storage.db.ExecContext(ctx, query, models.NotTested, id) - query := storage.db.Rebind("UPDATE testruns SET result = ? WHERE solution_id = ?") - _, err := storage.db.ExecContext(ctx, query, models.NotTested, id) - //FIXME: update result + tx,err := storage.db.Begin() if err != nil { return storage.HandlePgErr(err) } + tx.Exec("UPDATE solutions SET result = ? WHERE id = ?",models.NotTested, id) + tx.Exec("UPDATE testgroupruns SET result = ? WHERE solution_id = ?",models.NotTested, id) + tx.Exec("UPDATE testruns SET result = ? WHERE testgrouprun_id IN (SELECT id FROM tesgrouprun WHERE solution_id = ?)", models.NotTested, id) + err = tx.Commit() + if err != nil { + return storage.HandlePgErr(err) + } + //FIXME: update result return nil }