Fix SQLite deadlock when creating user
This avoids reading from the database after a transaction has been started in CreateUser(), fixing the deadlock that occurred before. Closes #53
This commit is contained in:
parent
f53ced382f
commit
1c58c64c7c
|
@ -155,16 +155,16 @@ func (db *datastore) dateSub(l int, unit string) string {
|
|||
}
|
||||
|
||||
func (db *datastore) CreateUser(u *User, collectionTitle string) error {
|
||||
if db.PostIDExists(u.Username) {
|
||||
return impart.HTTPError{http.StatusConflict, "Invalid collection name."}
|
||||
}
|
||||
|
||||
// New users get a `users` and `collections` row.
|
||||
t, err := db.Begin()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if db.PostIDExists(u.Username) {
|
||||
return impart.HTTPError{http.StatusConflict, "Invalid collection name."}
|
||||
}
|
||||
|
||||
// 1. Add to `users` table
|
||||
// NOTE: Assumes User's Password is already hashed!
|
||||
res, err := t.Exec("INSERT INTO users (username, password, email) VALUES (?, ?, ?)", u.Username, u.HashedPass, u.Email)
|
||||
|
|
Loading…
Reference in New Issue