Reduce db calls on normal invite-based signup

This removes an unnecessary database call after creating a user, and documents `db.CreateUser()` to make it clear that extra calls are unnecessary.
pull/303/head
Matt Baer 5 years ago
parent ca4a576c31
commit 5400f416c0
  1. 8
      account.go
  2. 1
      database.go

@ -1,5 +1,5 @@
/* /*
* Copyright © 2018-2019 A Bunch Tell LLC. * Copyright © 2018-2020 A Bunch Tell LLC.
* *
* This file is part of WriteFreely. * This file is part of WriteFreely.
* *
@ -168,11 +168,7 @@ func signupWithRegistration(app *App, signup userRegistration, w http.ResponseWr
// Log invite if needed // Log invite if needed
if signup.InviteCode != "" { if signup.InviteCode != "" {
cu, err := app.db.GetUserForAuth(signup.Alias) err = app.db.CreateInvitedUser(signup.InviteCode, u.ID)
if err != nil {
return nil, err
}
err = app.db.CreateInvitedUser(signup.InviteCode, cu.ID)
if err != nil { if err != nil {
return nil, err return nil, err
} }

@ -178,6 +178,7 @@ func (db *datastore) dateSub(l int, unit string) string {
return fmt.Sprintf("DATE_SUB(NOW(), INTERVAL %d %s)", l, unit) return fmt.Sprintf("DATE_SUB(NOW(), INTERVAL %d %s)", l, unit)
} }
// CreateUser creates a new user in the database from the given User, UPDATING it in the process with the user's ID.
func (db *datastore) CreateUser(cfg *config.Config, u *User, collectionTitle string) error { func (db *datastore) CreateUser(cfg *config.Config, u *User, collectionTitle string) error {
if db.PostIDExists(u.Username) { if db.PostIDExists(u.Username) {
return impart.HTTPError{http.StatusConflict, "Invalid collection name."} return impart.HTTPError{http.StatusConflict, "Invalid collection name."}

Loading…
Cancel
Save