forked from tangled.org/core
Monorepo for Tangled

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 235 } 236 236 237 237 func NewPull(tx *sql.Tx, pull *Pull) error { 238 - defer tx.Rollback() 239 - 240 238 _, err := tx.Exec(` 241 239 insert or ignore into repo_pull_seqs (repo_at, next_pull_id) 242 240 values (?, 1) ··· 291 289 insert into pull_submissions (pull_id, repo_at, round_number, patch, source_rev) 292 290 values (?, ?, ?, ?, ?) 293 291 `, 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 292 + return err 303 293 } 304 294 305 295 func GetPullAt(e Execer, repoAt syntax.ATURI, pullId int) (syntax.ATURI, error) {
+6 -1
appview/state/pull.go
··· 903 903 }, 904 904 }, 905 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 + } 906 911 907 - if err != nil { 912 + if err = tx.Commit(); err != nil { 908 913 log.Println("failed to create pull request", err) 909 914 s.pages.Notice(w, "pull", "Failed to create pull request. Try again later.") 910 915 return