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