Derive review timestamps at insertion and remove unused lookup
This commit is contained in:
@@ -15,16 +15,16 @@ import (
|
||||
const reviewColumns = `id, task_id, snapshot_n, stage, coalesce(agent_session_id, ''), vendor, model, state, result, error, created_at, finished_at, finding_states, finding_responses`
|
||||
|
||||
func (s *Store) CreateReview(ctx context.Context, r api.Review, definitionID string) error {
|
||||
return s.write(ctx, func(tx *sql.Tx, emit emitFunc) error {
|
||||
return insertReview(ctx, tx, emit, r, definitionID)
|
||||
})
|
||||
}
|
||||
|
||||
func insertReview(ctx context.Context, tx *sql.Tx, emit emitFunc, r api.Review, definitionID string) error {
|
||||
finishedAt := ""
|
||||
if r.FinishedAt != nil {
|
||||
finishedAt = formatTime(*r.FinishedAt)
|
||||
}
|
||||
return s.write(ctx, func(tx *sql.Tx, emit emitFunc) error {
|
||||
return insertReview(ctx, tx, emit, r, definitionID, finishedAt)
|
||||
})
|
||||
}
|
||||
|
||||
func insertReview(ctx context.Context, tx *sql.Tx, emit emitFunc, r api.Review, definitionID, finishedAt string) error {
|
||||
_, err := tx.ExecContext(ctx, `
|
||||
INSERT INTO reviews (id, task_id, snapshot_n, stage, definition_id, agent_session_id, vendor, model, state, error, created_at, finished_at)
|
||||
VALUES (?, ?, ?, ?, nullif(?, ''), nullif(?, ''), ?, ?, ?, ?, ?, ?)
|
||||
@@ -46,7 +46,7 @@ type Reviewer struct {
|
||||
func (s *Store) StartReviewers(ctx context.Context, projectID, definitionID string, reviewers []Reviewer, failed []api.Review) error {
|
||||
return s.write(ctx, func(tx *sql.Tx, emit emitFunc) error {
|
||||
for _, r := range failed {
|
||||
err := insertReview(ctx, tx, emit, r, definitionID, formatTime(*r.FinishedAt))
|
||||
err := insertReview(ctx, tx, emit, r, definitionID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -59,7 +59,7 @@ func (s *Store) StartReviewers(ctx context.Context, projectID, definitionID stri
|
||||
}
|
||||
r.Review.State = api.ReviewStateRunning
|
||||
r.Review.AgentSessionId = r.Session.Id
|
||||
err = insertReview(ctx, tx, emit, r.Review, definitionID, "")
|
||||
err = insertReview(ctx, tx, emit, r.Review, definitionID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -294,19 +294,6 @@ func settleReviews(ctx context.Context, tx *sql.Tx, pending []StageStart) ([]Sna
|
||||
return scanSnapshotRefs(rows)
|
||||
}
|
||||
|
||||
func (s *Store) ReviewDefinition(ctx context.Context, id string) (string, api.WorkflowDefinition, error) {
|
||||
defID := sql.NullString{}
|
||||
err := s.db.QueryRowContext(ctx, `SELECT definition_id FROM reviews WHERE id = ?`, id).Scan(&defID)
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return "", api.WorkflowDefinition{}, ErrNotFound
|
||||
}
|
||||
if err != nil || !defID.Valid {
|
||||
return "", api.WorkflowDefinition{}, err
|
||||
}
|
||||
def, err := loadDefinition(ctx, s.db, defID.String)
|
||||
return defID.String, def, err
|
||||
}
|
||||
|
||||
func (s *Store) GetReview(ctx context.Context, id string) (api.Review, error) {
|
||||
r, err := scanReview(s.db.QueryRowContext(ctx, `SELECT `+reviewColumns+` FROM reviews WHERE id = ?`, id))
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
|
||||
Reference in New Issue
Block a user