summaryrefslogtreecommitdiffstats
path: root/store
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2017-02-03 09:30:57 -0500
committerCorey Hulen <corey@hulen.com>2017-02-03 09:30:57 -0500
commitccb034382850b7e8ea924a4559e47ef44203155c (patch)
tree72026c58e6bb8e8ad679ac07476906281ffbb1d5 /store
parent177589b1e26fcabd7749dd0fbe8c39999c206609 (diff)
downloadchat-ccb034382850b7e8ea924a4559e47ef44203155c.tar.gz
chat-ccb034382850b7e8ea924a4559e47ef44203155c.tar.bz2
chat-ccb034382850b7e8ea924a4559e47ef44203155c.zip
Implement POST /users/ids endpoint for APIv4 (#5274)
Diffstat (limited to 'store')
-rw-r--r--store/sql_user_store.go12
-rw-r--r--store/sql_user_store_test.go78
2 files changed, 65 insertions, 25 deletions
diff --git a/store/sql_user_store.go b/store/sql_user_store.go
index 02cbb3fbf..827c5a064 100644
--- a/store/sql_user_store.go
+++ b/store/sql_user_store.go
@@ -808,8 +808,7 @@ func (us SqlUserStore) GetProfileByIds(userIds []string, allowFromCache bool) St
result := StoreResult{}
metrics := einterfaces.GetMetricsInterface()
- var users []*model.User
- userMap := make(map[string]*model.User)
+ users := []*model.User{}
props := make(map[string]interface{})
idQuery := ""
remainingUserIds := make([]string, 0)
@@ -818,13 +817,13 @@ func (us SqlUserStore) GetProfileByIds(userIds []string, allowFromCache bool) St
for _, userId := range userIds {
if cacheItem, ok := profileByIdsCache.Get(userId); ok {
u := cacheItem.(*model.User)
- userMap[u.Id] = u
+ users = append(users, u)
} else {
remainingUserIds = append(remainingUserIds, userId)
}
}
if metrics != nil {
- metrics.AddMemCacheHitCounter("Profile By Ids", float64(len(userMap)))
+ metrics.AddMemCacheHitCounter("Profile By Ids", float64(len(users)))
metrics.AddMemCacheMissCounter("Profile By Ids", float64(len(remainingUserIds)))
}
} else {
@@ -836,7 +835,7 @@ func (us SqlUserStore) GetProfileByIds(userIds []string, allowFromCache bool) St
// If everything came from the cache then just return
if len(remainingUserIds) == 0 {
- result.Data = userMap
+ result.Data = users
storeChannel <- result
close(storeChannel)
return
@@ -859,11 +858,10 @@ func (us SqlUserStore) GetProfileByIds(userIds []string, allowFromCache bool) St
u.Password = ""
u.AuthData = new(string)
*u.AuthData = ""
- userMap[u.Id] = u
profileByIdsCache.AddWithExpiresInSecs(u.Id, u, PROFILE_BY_IDS_CACHE_SEC)
}
- result.Data = userMap
+ result.Data = users
}
storeChannel <- result
diff --git a/store/sql_user_store_test.go b/store/sql_user_store_test.go
index fb04e95c9..449c6aa52 100644
--- a/store/sql_user_store_test.go
+++ b/store/sql_user_store_test.go
@@ -456,78 +456,120 @@ func TestUserStoreGetProfilesByIds(t *testing.T) {
if r1 := <-store.User().GetProfileByIds([]string{u1.Id}, false); r1.Err != nil {
t.Fatal(r1.Err)
} else {
- users := r1.Data.(map[string]*model.User)
+ users := r1.Data.([]*model.User)
if len(users) != 1 {
t.Fatal("invalid returned users")
}
- if users[u1.Id].Id != u1.Id {
- t.Fatal("invalid returned user")
+ found := false
+ for _, u := range users {
+ if u.Id == u1.Id {
+ found = true
+ }
+ }
+
+ if !found {
+ t.Fatal("missing user")
}
}
if r1 := <-store.User().GetProfileByIds([]string{u1.Id}, true); r1.Err != nil {
t.Fatal(r1.Err)
} else {
- users := r1.Data.(map[string]*model.User)
+ users := r1.Data.([]*model.User)
if len(users) != 1 {
t.Fatal("invalid returned users")
}
- if users[u1.Id].Id != u1.Id {
- t.Fatal("invalid returned user")
+ found := false
+ for _, u := range users {
+ if u.Id == u1.Id {
+ found = true
+ }
+ }
+
+ if !found {
+ t.Fatal("missing user")
}
}
if r1 := <-store.User().GetProfileByIds([]string{u1.Id, u2.Id}, true); r1.Err != nil {
t.Fatal(r1.Err)
} else {
- users := r1.Data.(map[string]*model.User)
+ users := r1.Data.([]*model.User)
if len(users) != 2 {
t.Fatal("invalid returned users")
}
- if users[u1.Id].Id != u1.Id {
- t.Fatal("invalid returned user")
+ found := false
+ for _, u := range users {
+ if u.Id == u1.Id {
+ found = true
+ }
+ }
+
+ if !found {
+ t.Fatal("missing user")
}
}
if r1 := <-store.User().GetProfileByIds([]string{u1.Id, u2.Id}, true); r1.Err != nil {
t.Fatal(r1.Err)
} else {
- users := r1.Data.(map[string]*model.User)
+ users := r1.Data.([]*model.User)
if len(users) != 2 {
t.Fatal("invalid returned users")
}
- if users[u1.Id].Id != u1.Id {
- t.Fatal("invalid returned user")
+ found := false
+ for _, u := range users {
+ if u.Id == u1.Id {
+ found = true
+ }
+ }
+
+ if !found {
+ t.Fatal("missing user")
}
}
if r1 := <-store.User().GetProfileByIds([]string{u1.Id, u2.Id}, false); r1.Err != nil {
t.Fatal(r1.Err)
} else {
- users := r1.Data.(map[string]*model.User)
+ users := r1.Data.([]*model.User)
if len(users) != 2 {
t.Fatal("invalid returned users")
}
- if users[u1.Id].Id != u1.Id {
- t.Fatal("invalid returned user")
+ found := false
+ for _, u := range users {
+ if u.Id == u1.Id {
+ found = true
+ }
+ }
+
+ if !found {
+ t.Fatal("missing user")
}
}
if r1 := <-store.User().GetProfileByIds([]string{u1.Id}, false); r1.Err != nil {
t.Fatal(r1.Err)
} else {
- users := r1.Data.(map[string]*model.User)
+ users := r1.Data.([]*model.User)
if len(users) != 1 {
t.Fatal("invalid returned users")
}
- if users[u1.Id].Id != u1.Id {
- t.Fatal("invalid returned user")
+ found := false
+ for _, u := range users {
+ if u.Id == u1.Id {
+ found = true
+ }
+ }
+
+ if !found {
+ t.Fatal("missing user")
}
}