summaryrefslogtreecommitdiffstats
path: root/store/sql_user_store.go
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2017-06-30 12:07:23 -0400
committerHarrison Healey <harrisonmhealey@gmail.com>2017-06-30 12:07:23 -0400
commit5507154992eedd323385c37e59b2008586b9aaa0 (patch)
treeb017d2a40207cb437b9aa84703990577539df9f8 /store/sql_user_store.go
parent6b77a054c25acb0437a58107c4592ad66c830993 (diff)
downloadchat-5507154992eedd323385c37e59b2008586b9aaa0.tar.gz
chat-5507154992eedd323385c37e59b2008586b9aaa0.tar.bz2
chat-5507154992eedd323385c37e59b2008586b9aaa0.zip
Add some basic sorting support for GET /users endpoint (#6801)
Diffstat (limited to 'store/sql_user_store.go')
-rw-r--r--store/sql_user_store.go48
1 files changed, 41 insertions, 7 deletions
diff --git a/store/sql_user_store.go b/store/sql_user_store.go
index 4aa6f6cfe..ab031ea19 100644
--- a/store/sql_user_store.go
+++ b/store/sql_user_store.go
@@ -756,7 +756,7 @@ type UserWithLastActivityAt struct {
LastActivityAt int64
}
-func (us SqlUserStore) GetRecentlyActiveUsersForTeam(teamId string) StoreChannel {
+func (us SqlUserStore) GetRecentlyActiveUsersForTeam(teamId string, offset, limit int) StoreChannel {
storeChannel := make(StoreChannel)
@@ -774,21 +774,55 @@ func (us SqlUserStore) GetRecentlyActiveUsersForTeam(teamId string) StoreChannel
INNER JOIN Status AS s ON s.UserId = t.UserId
WHERE t.TeamId = :TeamId
ORDER BY s.LastActivityAt DESC
- LIMIT 100
- `, map[string]interface{}{"TeamId": teamId}); err != nil {
- result.Err = model.NewLocAppError("SqlUserStore.GetRecentlyActiveUsers", "store.sql_user.get_recently_active_users.app_error", nil, err.Error())
+ LIMIT :Limit OFFSET :Offset
+ `, map[string]interface{}{"TeamId": teamId, "Offset": offset, "Limit": limit}); err != nil {
+ result.Err = model.NewAppError("SqlUserStore.GetRecentlyActiveUsers", "store.sql_user.get_recently_active_users.app_error", nil, err.Error(), http.StatusInternalServerError)
} else {
- userMap := make(map[string]*model.User)
+ userList := []*model.User{}
for _, userWithLastActivityAt := range users {
u := userWithLastActivityAt.User
u.Sanitize(map[string]bool{})
u.LastActivityAt = userWithLastActivityAt.LastActivityAt
- userMap[u.Id] = &u
+ userList = append(userList, &u)
}
- result.Data = userMap
+ result.Data = userList
+ }
+
+ storeChannel <- result
+ close(storeChannel)
+ }()
+
+ return storeChannel
+}
+
+func (us SqlUserStore) GetNewUsersForTeam(teamId string, offset, limit int) StoreChannel {
+
+ storeChannel := make(StoreChannel)
+
+ go func() {
+ result := StoreResult{}
+
+ var users []*model.User
+
+ if _, err := us.GetReplica().Select(&users, `
+ SELECT
+ u.*
+ FROM Users AS u
+ INNER JOIN TeamMembers AS t ON u.Id = t.UserId
+ WHERE t.TeamId = :TeamId
+ ORDER BY u.CreateAt DESC
+ LIMIT :Limit OFFSET :Offset
+ `, map[string]interface{}{"TeamId": teamId, "Offset": offset, "Limit": limit}); err != nil {
+ result.Err = model.NewAppError("SqlUserStore.GetNewUsersForTeam", "store.sql_user.get_new_users.app_error", nil, err.Error(), http.StatusInternalServerError)
+ } else {
+ for _, u := range users {
+ u.Sanitize(map[string]bool{})
+ }
+
+ result.Data = users
}
storeChannel <- result