Add support for adding multiple events to the database atomically

This commit is contained in:
2013-09-05 21:06:15 -04:00
parent fcf61701cc
commit 65e692b701
2 changed files with 18 additions and 21 deletions

View File

@ -162,18 +162,13 @@ func putEvents(w http.ResponseWriter, r *http.Request, user *User) {
error_message = err.Error()
return
}
for _, event := range events.Events {
err = adb.DatabaseAddEvent(user, event)
if err != nil {
//TODO should probably do this in a way that the caller knows how many of these have failed and doesn't re-try sending ones that succeeded
//i.e. add this to the return codes or something
//OR put all the DatabaseAddEvent's inside a SQL transaction, and rollback on any failure
error_message = err.Error()
return
}
err = adb.DatabaseAddEvents(user, events.Events)
if err != nil {
error_message = err.Error()
return
}
broadcastToPollers(user.Id, events.Events[0]) //TODO support more than one user
broadcastToPollers(user.Id, events.Events[0])
}
func eventHandler(w http.ResponseWriter, r *http.Request) {