fix: correct transaction
This commit is contained in:
parent
579cdaa7f3
commit
f7a2ec7183
1 changed files with 16 additions and 6 deletions
|
@ -24,13 +24,17 @@ func NewSolutionStorage(db *sqlx.DB, logger *zap.Logger) *SolutionStorage {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: testing graph
|
||||
|
||||
func updateResult(ctx context.Context, participantId int32, taskId int32) error {
|
||||
tx,err := storage.db.Begin()
|
||||
if err != nil {
|
||||
return storage.HandlePgErr(err)
|
||||
}
|
||||
tx.Exec("UPDATE participant_subtask AS ps SET best_score = (SELECT COALESCE(max(score),0) FROM subtaskruns WHERE subtask_id = ps.subtask_id AND solution_id IN (SELECT id FROM solutions WHERE participant_id=ps.participant_id)) WHERE participant_id = 2 AND subtask_id IN (SELECT id FROM subtasks WHERE task_id = 2)",participantId,taskId)
|
||||
tx.Exec("UPDATE participant_task SET best_score = (select max(best_score) from participant_subtask WHERE participant_id = ? AND subtask_id IN (SELECT id FROM subtask WHERE task_id = ?)) WHERE participant_id = ? AND task_id = ?",participantId,taskId,participantId,taskId)
|
||||
query:=tx.Rebind("UPDATE participant_subtask AS ps SET best_score = (SELECT COALESCE(max(score),0) FROM subtaskruns WHERE subtask_id = ps.subtask_id AND solution_id IN (SELECT id FROM solutions WHERE participant_id=ps.participant_id)) WHERE participant_id = 2 AND subtask_id IN (SELECT id FROM subtasks WHERE task_id = 2)")
|
||||
tx.QueryxContext(ctx,query,participantId,taskId)
|
||||
query=tx.Rebind("UPDATE participant_task SET best_score = (select max(best_score) from participant_subtask WHERE participant_id = ? AND subtask_id IN (SELECT id FROM subtask WHERE task_id = ?)) WHERE participant_id = ? AND task_id = ?")
|
||||
tx.QueryxContext(ctx,query,participantId,taskId,participantId,taskId)
|
||||
err = tx.Commit()
|
||||
if err != nil {
|
||||
return storage.HandlePgErr(err)
|
||||
|
@ -83,14 +87,20 @@ func (storage *SolutionStorage) RejudgeSolution(ctx context.Context, id int32) e
|
|||
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)
|
||||
query:=tx.Rebind("UPDATE solutions SET result = ? WHERE id = ?")
|
||||
tx.QueryxContext(ctx,query,models.NotTested, id)
|
||||
query=tx.Rebind("UPDATE subtaskruns SET result = ?,score = 0 WHERE solution_id = ?")
|
||||
tx.QueryxContext(ctx,query,models.NotTested, id)
|
||||
query=tx.Rebind("UPDATE testruns SET result = ?, score = 0 WHERE testgrouprun_id IN (SELECT id FROM tesgrouprun WHERE solution_id = ?)")
|
||||
tx.QueryxContext(ctx,query,models.NotTested, id)
|
||||
err = tx.Commit()
|
||||
var solution models.Solution
|
||||
query := storage.db.Rebind("SELECT * from solutions WHERE id=? LIMIT 1")
|
||||
err := storage.db.GetContext(ctx, &solution, query, id)
|
||||
if err != nil {
|
||||
return storage.HandlePgErr(err)
|
||||
}
|
||||
//FIXME: update result
|
||||
updateResult(ctx,solution.ParticipantId,TaskId);
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue