From bbf2bd85c75579d8fc8f4247f22ca0f1748e036f Mon Sep 17 00:00:00 2001 From: oppiliappan Date: Sat, 10 May 2025 22:32:02 +0100 Subject: [PATCH] appview: pulls: make NewPull more transactional the current transaction model only rollsback on db failures. this changeset makes the transaction encapsulate the entire NewPull flow. if creating the pds record fails, the db is still rolled back. --- appview/db/pulls.go | 12 +----------- appview/state/pull.go | 7 ++++++- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/appview/db/pulls.go b/appview/db/pulls.go index da6e086e..53622ab6 100644 --- a/appview/db/pulls.go +++ b/appview/db/pulls.go @@ -235,8 +235,6 @@ func (s PullSubmission) AsFormatPatch() []patchutil.FormatPatch { } func NewPull(tx *sql.Tx, pull *Pull) error { - defer tx.Rollback() - _, err := tx.Exec(` insert or ignore into repo_pull_seqs (repo_at, next_pull_id) values (?, 1) @@ -291,15 +289,7 @@ func NewPull(tx *sql.Tx, pull *Pull) error { insert into pull_submissions (pull_id, repo_at, round_number, patch, source_rev) values (?, ?, ?, ?, ?) `, pull.PullId, pull.RepoAt, 0, pull.Submissions[0].Patch, pull.Submissions[0].SourceRev) - if err != nil { - return err - } - - if err := tx.Commit(); err != nil { - return err - } - - return nil + return err } func GetPullAt(e Execer, repoAt syntax.ATURI, pullId int) (syntax.ATURI, error) { diff --git a/appview/state/pull.go b/appview/state/pull.go index 7a08b697..1fc229da 100644 --- a/appview/state/pull.go +++ b/appview/state/pull.go @@ -903,13 +903,18 @@ func (s *State) createPullRequest( }, }, }) - if err != nil { log.Println("failed to create pull request", err) s.pages.Notice(w, "pull", "Failed to create pull request. Try again later.") return } + if err = tx.Commit(); err != nil { + log.Println("failed to create pull request", err) + s.pages.Notice(w, "pull", "Failed to create pull request. Try again later.") + return + } + s.pages.HxLocation(w, fmt.Sprintf("/%s/pulls/%d", f.OwnerSlashRepo(), pullId)) } -- 2.51.2