Skip to content

Commit

Permalink
chore(PUT /bulk/policy): use single transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
johnfrancismccann committed Jan 20, 2022
1 parent 6b67a98 commit 409cd79
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions arborist/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,18 @@ func (server *Server) overwritePolicy(w http.ResponseWriter, r *http.Request, po
return nil
}

func (server *Server) bulkOverwritePolicy(policies []Policy) *ErrorResponse {
overwritePolicies := func (tx *sqlx.Tx) *ErrorResponse {
for _, policy := range policies {
policy.updateInDb(tx)
}
return nil
}

transactify(server.db, overwritePolicies)
return nil
}

func (server *Server) handlePolicyOverwrite(w http.ResponseWriter, r *http.Request, body []byte) {
policy := &Policy{}
err := json.Unmarshal(body, policy)
Expand Down Expand Up @@ -768,9 +780,7 @@ func (server *Server) handleBulkPoliciesOverwrite(w http.ResponseWriter, r *http
return
}

for _, policy := range policies {
server.overwritePolicy(w, r, policy)
}
server.bulkOverwritePolicy(policies)
updated := struct {
Updated []Policy `json:"updated"`
}{
Expand Down

0 comments on commit 409cd79

Please sign in to comment.