forked from tangled.org/core
this repo has no description

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.

authored by oppi.li and committed by Tangled bbf2bd85 07628ed9

Changed files
+7 -12
appview
db
state
+1 -11
appview/db/pulls.go
··· 235 } 236 237 func NewPull(tx *sql.Tx, pull *Pull) error { 238 - defer tx.Rollback() 239 - 240 _, err := tx.Exec(` 241 insert or ignore into repo_pull_seqs (repo_at, next_pull_id) 242 values (?, 1) ··· 291 insert into pull_submissions (pull_id, repo_at, round_number, patch, source_rev) 292 values (?, ?, ?, ?, ?) 293 `, pull.PullId, pull.RepoAt, 0, pull.Submissions[0].Patch, pull.Submissions[0].SourceRev) 294 - if err != nil { 295 - return err 296 - } 297 - 298 - if err := tx.Commit(); err != nil { 299 - return err 300 - } 301 - 302 - return nil 303 } 304 305 func GetPullAt(e Execer, repoAt syntax.ATURI, pullId int) (syntax.ATURI, error) {
··· 235 } 236 237 func NewPull(tx *sql.Tx, pull *Pull) error { 238 _, err := tx.Exec(` 239 insert or ignore into repo_pull_seqs (repo_at, next_pull_id) 240 values (?, 1) ··· 289 insert into pull_submissions (pull_id, repo_at, round_number, patch, source_rev) 290 values (?, ?, ?, ?, ?) 291 `, pull.PullId, pull.RepoAt, 0, pull.Submissions[0].Patch, pull.Submissions[0].SourceRev) 292 + return err 293 } 294 295 func GetPullAt(e Execer, repoAt syntax.ATURI, pullId int) (syntax.ATURI, error) {
+6 -1
appview/state/pull.go
··· 903 }, 904 }, 905 }) 906 907 - if err != nil { 908 log.Println("failed to create pull request", err) 909 s.pages.Notice(w, "pull", "Failed to create pull request. Try again later.") 910 return
··· 903 }, 904 }, 905 }) 906 + if err != nil { 907 + log.Println("failed to create pull request", err) 908 + s.pages.Notice(w, "pull", "Failed to create pull request. Try again later.") 909 + return 910 + } 911 912 + if err = tx.Commit(); err != nil { 913 log.Println("failed to create pull request", err) 914 s.pages.Notice(w, "pull", "Failed to create pull request. Try again later.") 915 return