Monorepo for Tangled tangled.org

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.

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
··· 893 }, 894 }, 895 }) 896 897 - if err != nil { 898 log.Println("failed to create pull request", err) 899 s.pages.Notice(w, "pull", "Failed to create pull request. Try again later.") 900 return
··· 893 }, 894 }, 895 }) 896 + if err != nil { 897 + log.Println("failed to create pull request", err) 898 + s.pages.Notice(w, "pull", "Failed to create pull request. Try again later.") 899 + return 900 + } 901 902 + if err = tx.Commit(); err != nil { 903 log.Println("failed to create pull request", err) 904 s.pages.Notice(w, "pull", "Failed to create pull request. Try again later.") 905 return