From 5400f416c016a22f570ad4af061d298038b925f2 Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Mon, 20 Apr 2020 18:21:01 -0400 Subject: [PATCH] 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. --- account.go | 8 ++------ database.go | 1 + 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/account.go b/account.go index d32f503..f3399e4 100644 --- a/account.go +++ b/account.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. * @@ -168,11 +168,7 @@ func signupWithRegistration(app *App, signup userRegistration, w http.ResponseWr // Log invite if needed if signup.InviteCode != "" { - cu, err := app.db.GetUserForAuth(signup.Alias) - if err != nil { - return nil, err - } - err = app.db.CreateInvitedUser(signup.InviteCode, cu.ID) + err = app.db.CreateInvitedUser(signup.InviteCode, u.ID) if err != nil { return nil, err } diff --git a/database.go b/database.go index a1e8642..0eee612 100644 --- a/database.go +++ b/database.go @@ -178,6 +178,7 @@ func (db *datastore) dateSub(l int, unit string) string { 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 { if db.PostIDExists(u.Username) { return impart.HTTPError{http.StatusConflict, "Invalid collection name."}