forked from tangled.org/core
Monorepo for Tangled — https://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
···
}
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)
···
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) {
+6 -1
appview/state/pull.go
···
},
},
})
+
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 != nil {
+
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