commenter_get.go: single query commenterGetByCommenterToken
Closes https://gitlab.com/commento/commento/merge_requests/125
This commit is contained in:
parent
885c4dea9f
commit
042fda0e8c
@ -50,22 +50,22 @@ func commenterGetByCommenterToken(commenterToken string) (commenter, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
statement := `
|
statement := `
|
||||||
SELECT commenterHex
|
SELECT commenters.commenterHex, commenters.email, commenters.name, commenters.link, commenters.photo, commenters.provider, commenters.joinDate
|
||||||
FROM commenterSessions
|
FROM commenterSessions
|
||||||
|
JOIN commenters ON commenterSessions.commenterHex = commenters.commenterHex
|
||||||
WHERE commenterToken = $1;
|
WHERE commenterToken = $1;
|
||||||
`
|
`
|
||||||
row := db.QueryRow(statement, commenterToken)
|
row := db.QueryRow(statement, commenterToken)
|
||||||
|
|
||||||
var commenterHex string
|
c := commenter{}
|
||||||
if err := row.Scan(&commenterHex); err != nil {
|
if err := row.Scan(&c.CommenterHex, &c.Email, &c.Name, &c.Link, &c.Photo, &c.Provider, &c.JoinDate); err != nil {
|
||||||
// TODO: is the only error?
|
// TODO: is this the only error?
|
||||||
return commenter{}, errorNoSuchToken
|
return commenter{}, errorNoSuchToken
|
||||||
}
|
}
|
||||||
|
|
||||||
if commenterHex == "none" {
|
if c.CommenterHex == "none" {
|
||||||
return commenter{}, errorNoSuchToken
|
return commenter{}, errorNoSuchToken
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: use a join instead of two queries?
|
return c, nil
|
||||||
return commenterGetByHex(commenterHex)
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user