summaryrefslogtreecommitdiffstats
path: root/store/sql_user_store.go
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2017-02-03 15:17:34 -0500
committerGitHub <noreply@github.com>2017-02-03 15:17:34 -0500
commit7ff2aef7facdeb025a1651ef411fceb3d81932c1 (patch)
tree7ea2f7b89e4b4c1acf3ca021377b0166089ba397 /store/sql_user_store.go
parent948b557453550646ad3213cb4144055eb7db0d69 (diff)
downloadchat-7ff2aef7facdeb025a1651ef411fceb3d81932c1.tar.gz
chat-7ff2aef7facdeb025a1651ef411fceb3d81932c1.tar.bz2
chat-7ff2aef7facdeb025a1651ef411fceb3d81932c1.zip
Implement GET /users endpoint for APIv4 (#5277)
Diffstat (limited to 'store/sql_user_store.go')
-rw-r--r--store/sql_user_store.go60
1 files changed, 39 insertions, 21 deletions
diff --git a/store/sql_user_store.go b/store/sql_user_store.go
index 827c5a064..7ca33fd78 100644
--- a/store/sql_user_store.go
+++ b/store/sql_user_store.go
@@ -510,16 +510,13 @@ func (us SqlUserStore) GetAllProfiles(offset int, limit int) StoreChannel {
result.Err = model.NewLocAppError("SqlUserStore.GetAllProfiles", "store.sql_user.get_profiles.app_error", nil, err.Error())
} else {
- userMap := make(map[string]*model.User)
-
for _, u := range users {
u.Password = ""
u.AuthData = new(string)
*u.AuthData = ""
- userMap[u.Id] = u
}
- result.Data = userMap
+ result.Data = users
}
storeChannel <- result
@@ -562,16 +559,13 @@ func (us SqlUserStore) GetProfiles(teamId string, offset int, limit int) StoreCh
result.Err = model.NewLocAppError("SqlUserStore.GetProfiles", "store.sql_user.get_profiles.app_error", nil, err.Error())
} else {
- userMap := make(map[string]*model.User)
-
for _, u := range users {
u.Password = ""
u.AuthData = new(string)
*u.AuthData = ""
- userMap[u.Id] = u
}
- result.Data = userMap
+ result.Data = users
}
storeChannel <- result
@@ -598,7 +592,38 @@ func (us SqlUserStore) InvalidateProfilesInChannelCache(channelId string) {
profilesInChannelCache.Remove(channelId)
}
-func (us SqlUserStore) GetProfilesInChannel(channelId string, offset int, limit int, allowFromCache bool) StoreChannel {
+func (us SqlUserStore) GetProfilesInChannel(channelId string, offset int, limit int) StoreChannel {
+
+ storeChannel := make(StoreChannel)
+
+ go func() {
+ result := StoreResult{}
+
+ var users []*model.User
+
+ query := "SELECT Users.* FROM Users, ChannelMembers WHERE ChannelMembers.ChannelId = :ChannelId AND Users.Id = ChannelMembers.UserId AND Users.DeleteAt = 0 ORDER BY Users.Username ASC LIMIT :Limit OFFSET :Offset"
+
+ if _, err := us.GetReplica().Select(&users, query, map[string]interface{}{"ChannelId": channelId, "Offset": offset, "Limit": limit}); err != nil {
+ result.Err = model.NewLocAppError("SqlUserStore.GetProfilesInChannel", "store.sql_user.get_profiles.app_error", nil, err.Error())
+ } else {
+
+ for _, u := range users {
+ u.Password = ""
+ u.AuthData = new(string)
+ *u.AuthData = ""
+ }
+
+ result.Data = users
+ }
+
+ storeChannel <- result
+ close(storeChannel)
+ }()
+
+ return storeChannel
+}
+
+func (us SqlUserStore) GetAllProfilesInChannel(channelId string, allowFromCache bool) StoreChannel {
storeChannel := make(StoreChannel)
@@ -606,7 +631,7 @@ func (us SqlUserStore) GetProfilesInChannel(channelId string, offset int, limit
result := StoreResult{}
metrics := einterfaces.GetMetricsInterface()
- if allowFromCache && offset == -1 && limit == -1 {
+ if allowFromCache {
if cacheItem, ok := profilesInChannelCache.Get(channelId); ok {
if metrics != nil {
metrics.IncrementMemCacheHitCounter("Profiles in Channel")
@@ -630,12 +655,8 @@ func (us SqlUserStore) GetProfilesInChannel(channelId string, offset int, limit
query := "SELECT Users.* FROM Users, ChannelMembers WHERE ChannelMembers.ChannelId = :ChannelId AND Users.Id = ChannelMembers.UserId AND Users.DeleteAt = 0"
- if limit >= 0 && offset >= 0 {
- query += " ORDER BY Users.Username ASC LIMIT :Limit OFFSET :Offset"
- }
-
- if _, err := us.GetReplica().Select(&users, query, map[string]interface{}{"ChannelId": channelId, "Offset": offset, "Limit": limit}); err != nil {
- result.Err = model.NewLocAppError("SqlUserStore.GetProfilesInChannel", "store.sql_user.get_profiles.app_error", nil, err.Error())
+ if _, err := us.GetReplica().Select(&users, query, map[string]interface{}{"ChannelId": channelId}); err != nil {
+ result.Err = model.NewLocAppError("SqlUserStore.GetAllProfilesInChannel", "store.sql_user.get_profiles.app_error", nil, err.Error())
} else {
userMap := make(map[string]*model.User)
@@ -649,7 +670,7 @@ func (us SqlUserStore) GetProfilesInChannel(channelId string, offset int, limit
result.Data = userMap
- if allowFromCache && offset == -1 && limit == -1 {
+ if allowFromCache {
profilesInChannelCache.AddWithExpiresInSecs(channelId, userMap, PROFILES_IN_CHANNEL_CACHE_SEC)
}
}
@@ -688,16 +709,13 @@ func (us SqlUserStore) GetProfilesNotInChannel(teamId string, channelId string,
result.Err = model.NewLocAppError("SqlUserStore.GetProfilesNotInChannel", "store.sql_user.get_profiles.app_error", nil, err.Error())
} else {
- userMap := make(map[string]*model.User)
-
for _, u := range users {
u.Password = ""
u.AuthData = new(string)
*u.AuthData = ""
- userMap[u.Id] = u
}
- result.Data = userMap
+ result.Data = users
}
storeChannel <- result