From 042fda0e8c5f01dc6c2942a3c17d8c677d8ed4be Mon Sep 17 00:00:00 2001 From: Dave Date: Sun, 24 Nov 2019 09:53:54 +0000 Subject: [PATCH] commenter_get.go: single query commenterGetByCommenterToken Closes https://gitlab.com/commento/commento/merge_requests/125 --- api/commenter_get.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/api/commenter_get.go b/api/commenter_get.go index 2ea284d..de9bfd9 100644 --- a/api/commenter_get.go +++ b/api/commenter_get.go @@ -50,22 +50,22 @@ func commenterGetByCommenterToken(commenterToken string) (commenter, error) { } statement := ` - SELECT commenterHex + SELECT commenters.commenterHex, commenters.email, commenters.name, commenters.link, commenters.photo, commenters.provider, commenters.joinDate FROM commenterSessions + JOIN commenters ON commenterSessions.commenterHex = commenters.commenterHex WHERE commenterToken = $1; ` row := db.QueryRow(statement, commenterToken) - var commenterHex string - if err := row.Scan(&commenterHex); err != nil { - // TODO: is the only error? + c := commenter{} + if err := row.Scan(&c.CommenterHex, &c.Email, &c.Name, &c.Link, &c.Photo, &c.Provider, &c.JoinDate); err != nil { + // TODO: is this the only error? return commenter{}, errorNoSuchToken } - if commenterHex == "none" { + if c.CommenterHex == "none" { return commenter{}, errorNoSuchToken } - // TODO: use a join instead of two queries? - return commenterGetByHex(commenterHex) + return c, nil }