From 4397b7afc87ad0213674777d6ad335ffc4031ccf Mon Sep 17 00:00:00 2001 From: Azareal Date: Thu, 6 Dec 2018 21:54:20 +1000 Subject: [PATCH] Make Users.BulkGetMap a little more tolerant of duplicate IDs. --- common/user_store.go | 19 ++++++------------- routes.go | 2 ++ 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/common/user_store.go b/common/user_store.go index 4e90429e..33e0d8e2 100644 --- a/common/user_store.go +++ b/common/user_store.go @@ -3,7 +3,6 @@ package common import ( "database/sql" "errors" - "log" "strconv" "github.com/Azareal/Gosora/query_gen" @@ -88,8 +87,12 @@ func (mus *DefaultUserStore) DirtyGet(id int) *User { func (mus *DefaultUserStore) Get(id int) (*User, error) { user, err := mus.cache.Get(id) if err == nil { + //log.Print("cached user") + //log.Print(string(debug.Stack())) + //log.Println("") return user, nil } + //log.Print("uncached user") user = &User{ID: id, Loggedin: true} err = mus.get.QueryRow(id).Scan(&user.Name, &user.Group, &user.Active, &user.IsSuperAdmin, &user.Session, &user.Email, &user.RawAvatar, &user.Message, &user.URLPrefix, &user.URLName, &user.Level, &user.Score, &user.Liked, &user.LastIP, &user.TempGroup) @@ -206,19 +209,9 @@ func (mus *DefaultUserStore) BulkGetMap(ids []int) (list map[int]*User, err erro sidList += strconv.Itoa(id) + "," } } - - // We probably don't need this, but it might be useful in case of bugs in BulkCascadeGetMap - if sidList == "" { - // TODO: Bulk log this - if Dev.DebugMode { - log.Print("This data is sampled later in the BulkCascadeGetMap function, so it might miss the cached IDs") - log.Print("idCount", idCount) - log.Print("ids", ids) - log.Print("list", list) - } - return list, errors.New("We weren't able to find a user, but we don't know which one") + if sidList != "" { + sidList = sidList[0 : len(sidList)-1] } - sidList = sidList[0 : len(sidList)-1] err = errors.New("Unable to find the users with the following IDs: " + sidList) } diff --git a/routes.go b/routes.go index 48523598..121fd76d 100644 --- a/routes.go +++ b/routes.go @@ -11,6 +11,7 @@ import ( "encoding/hex" "encoding/json" "errors" + "log" "net/http" "strconv" "strings" @@ -100,6 +101,7 @@ func routeAPI(w http.ResponseWriter, r *http.Request, user common.User) common.R // Might not want to error here, if the account was deleted properly, we might want to figure out how we should handle deletions in general list, err := common.Users.BulkGetMap(actors) if err != nil { + log.Print("actors:", actors) return common.InternalErrorJS(err, w, r) }