Make Users.BulkGetMap a little more tolerant of duplicate IDs.
This commit is contained in:
parent
a20078d83b
commit
4397b7afc8
|
@ -3,7 +3,6 @@ package common
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"errors"
|
"errors"
|
||||||
"log"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/Azareal/Gosora/query_gen"
|
"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) {
|
func (mus *DefaultUserStore) Get(id int) (*User, error) {
|
||||||
user, err := mus.cache.Get(id)
|
user, err := mus.cache.Get(id)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
//log.Print("cached user")
|
||||||
|
//log.Print(string(debug.Stack()))
|
||||||
|
//log.Println("")
|
||||||
return user, nil
|
return user, nil
|
||||||
}
|
}
|
||||||
|
//log.Print("uncached user")
|
||||||
|
|
||||||
user = &User{ID: id, Loggedin: true}
|
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)
|
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) + ","
|
sidList += strconv.Itoa(id) + ","
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if sidList != "" {
|
||||||
// We probably don't need this, but it might be useful in case of bugs in BulkCascadeGetMap
|
sidList = sidList[0 : len(sidList)-1]
|
||||||
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")
|
|
||||||
}
|
}
|
||||||
sidList = sidList[0 : len(sidList)-1]
|
|
||||||
|
|
||||||
err = errors.New("Unable to find the users with the following IDs: " + sidList)
|
err = errors.New("Unable to find the users with the following IDs: " + sidList)
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"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
|
// 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)
|
list, err := common.Users.BulkGetMap(actors)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Print("actors:", actors)
|
||||||
return common.InternalErrorJS(err, w, r)
|
return common.InternalErrorJS(err, w, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue