From 62969581bf81f3e5683b93cd428e73893af14ed2 Mon Sep 17 00:00:00 2001 From: Howl Date: Sat, 9 Apr 2016 23:58:27 +0200 Subject: [PATCH] Badges are useless on most requests. --- app/v1/friend.go | 18 ++---------------- app/v1/user.go | 9 +++------ 2 files changed, 5 insertions(+), 22 deletions(-) diff --git a/app/v1/friend.go b/app/v1/friend.go index 950fbae..4617571 100644 --- a/app/v1/friend.go +++ b/app/v1/friend.go @@ -4,7 +4,6 @@ import ( "database/sql" "encoding/json" "strconv" - "strings" "time" "github.com/osuripple/api/common" @@ -44,7 +43,7 @@ func FriendsGET(md common.MethodData) (r common.Response) { SELECT users.id, users.username, users.register_datetime, users.rank, users.latest_activity, - users_stats.username_aka, users_stats.badges_shown, + users_stats.username_aka, users_stats.country, users_stats.show_country FROM users_relationships LEFT JOIN users @@ -88,9 +87,8 @@ func friendPuts(md common.MethodData, row *sql.Rows) (user friendData) { registeredOn := int64(0) latestActivity := int64(0) - var badges string var showcountry bool - err = row.Scan(&user.ID, &user.Username, ®isteredOn, &user.Rank, &latestActivity, &user.UsernameAKA, &badges, &user.Country, &showcountry) + err = row.Scan(&user.ID, &user.Username, ®isteredOn, &user.Rank, &latestActivity, &user.UsernameAKA, &user.Country, &showcountry) if err != nil { md.Err(err) return @@ -99,18 +97,6 @@ func friendPuts(md common.MethodData, row *sql.Rows) (user friendData) { user.RegisteredOn = time.Unix(registeredOn, 0) user.LatestActivity = time.Unix(latestActivity, 0) - badgesSl := strings.Split(badges, ",") - for _, badge := range badgesSl { - if badge != "" && badge != "0" { - // We are ignoring errors because who really gives a shit if something's gone wrong on our end in this - // particular thing, we can just silently ignore this. - nb, err := strconv.Atoi(badge) - if err == nil && nb != 0 { - user.Badges = append(user.Badges, nb) - } - } - } - // If the user wants to stay anonymous, don't show their country. // This can be overriden if we have the ReadConfidential privilege and the user we are accessing is the token owner. if !(showcountry || (md.User.Privileges.HasPrivilegeReadConfidential() && user.ID == md.ID())) { diff --git a/app/v1/user.go b/app/v1/user.go index 2b28b3b..84a892e 100644 --- a/app/v1/user.go +++ b/app/v1/user.go @@ -20,7 +20,6 @@ type userData struct { Rank int `json:"rank"` LatestActivity time.Time `json:"latest_activity"` Country string `json:"country"` - Badges []int `json:"badges"` } // UserByIDGET is the API handler for GET /users/id/:id @@ -58,7 +57,7 @@ func UserByNameGET(md common.MethodData) (r common.Response) { query := ` SELECT users.id, users.username, register_datetime, rank, - latest_activity, users_stats.username_aka, users_stats.badges_shown, + latest_activity, users_stats.username_aka, users_stats.country, users_stats.show_country FROM users LEFT JOIN users_stats @@ -76,10 +75,9 @@ func userPuts(md common.MethodData, row *sql.Row) (r common.Response) { var ( registeredOn int64 latestActivity int64 - badges string showCountry bool ) - err = row.Scan(&user.ID, &user.Username, ®isteredOn, &user.Rank, &latestActivity, &user.UsernameAKA, &badges, &user.Country, &showCountry) + err = row.Scan(&user.ID, &user.Username, ®isteredOn, &user.Rank, &latestActivity, &user.UsernameAKA, &user.Country, &showCountry) switch { case err == sql.ErrNoRows: r.Code = 404 @@ -94,8 +92,6 @@ func userPuts(md common.MethodData, row *sql.Row) (r common.Response) { user.RegisteredOn = time.Unix(registeredOn, 0) user.LatestActivity = time.Unix(latestActivity, 0) - user.Badges = badgesToArray(badges) - user.Country = genCountry(md, user.ID, showCountry, user.Country) r.Code = 200 @@ -174,6 +170,7 @@ type userFullData struct { Mania modeData `json:"mania"` PlayStyle int `json:"play_style"` FavouriteMode int `json:"favourite_mode"` + Badges []int `json:"badges"` } // UserFullGET gets all of an user's information, with one exception: their userpage.