fix: improve rejudge

This commit is contained in:
dragonmuffin 2024-08-17 18:41:37 +05:00
parent 48ad3a5461
commit 5832e83460
2 changed files with 15 additions and 10 deletions

View file

@ -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 {

View file

@ -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
}