merge token and uuid lookups to reduce roundtrips

pull/13/head
Up 6 months ago
parent 81853b1863
commit f0c283af42
No known key found for this signature in database
GPG Key ID: 3B75CD7439FEB388

@ -82,17 +82,22 @@ func tokenFromRequest(r *http.Request) ([]byte, error) {
}
func uuidFromRequest(r *http.Request) ([]byte, error) {
_, uuid, err := tokenAndUuidFromRequest(r)
return uuid, err
}
func tokenAndUuidFromRequest(r *http.Request) ([]byte, []byte, error) {
token, err := tokenFromRequest(r)
if err != nil {
return nil, err
return nil, nil, err
}
uuid, err := db.FetchUUIDFromToken(token)
if err != nil {
return nil, fmt.Errorf("failed to validate token: %s", err)
return nil, nil, fmt.Errorf("failed to validate token: %s", err)
}
return uuid, nil
return token, uuid, nil
}
func httpError(w http.ResponseWriter, r *http.Request, err error, code int) {

@ -163,7 +163,7 @@ func handleGameClassicSessionCount(w http.ResponseWriter, r *http.Request) {
}
func handleSaveData(w http.ResponseWriter, r *http.Request) {
uuid, err := uuidFromRequest(r)
token, uuid, err := tokenAndUuidFromRequest(r)
if err != nil {
httpError(w, r, err, http.StatusBadRequest)
return
@ -212,13 +212,6 @@ func handleSaveData(w http.ResponseWriter, r *http.Request) {
}
}
var token []byte
token, err = tokenFromRequest(r)
if err != nil {
httpError(w, r, err, http.StatusBadRequest)
return
}
var active bool
if r.URL.Path == "/savedata/get" {
if datatype == 0 {
@ -337,13 +330,7 @@ type CombinedSaveData struct {
// TODO wrap this in a transaction
func handleSaveData2(w http.ResponseWriter, r *http.Request) {
var token []byte
token, err := tokenFromRequest(r)
if err != nil {
httpError(w, r, err, http.StatusBadRequest)
return
}
uuid, err := uuidFromRequest(r)
token, uuid, err := tokenAndUuidFromRequest(r)
if err != nil {
httpError(w, r, err, http.StatusBadRequest)
return

Loading…
Cancel
Save