mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
api4/user: Deduplicate userids for getUsersByIds endpoint (#24344)
This commit is contained in:
parent
4145fd2f4e
commit
639d73b3e7
@ -957,6 +957,10 @@ func getUsersByIds(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
// we remove the duplicate IDs as it can bring a significant load to the
|
||||
// database.
|
||||
userIDs = model.RemoveDuplicateStrings(userIDs)
|
||||
|
||||
sinceString := r.URL.Query().Get("since")
|
||||
|
||||
options := &store.UserGetByIdsOpts{
|
||||
|
@ -231,13 +231,17 @@ func localGetUsers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func localGetUsersByIds(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
userIds := model.ArrayFromJSON(r.Body)
|
||||
userIDs := model.ArrayFromJSON(r.Body)
|
||||
|
||||
if len(userIds) == 0 {
|
||||
if len(userIDs) == 0 {
|
||||
c.SetInvalidParam("user_ids")
|
||||
return
|
||||
}
|
||||
|
||||
// we remove the duplicate IDs as it can bring a significant load to the
|
||||
// database.
|
||||
userIDs = model.RemoveDuplicateStrings(userIDs)
|
||||
|
||||
sinceString := r.URL.Query().Get("since")
|
||||
|
||||
options := &store.UserGetByIdsOpts{
|
||||
@ -253,7 +257,7 @@ func localGetUsersByIds(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
options.Since = since
|
||||
}
|
||||
|
||||
users, appErr := c.App.GetUsersByIds(userIds, options)
|
||||
users, appErr := c.App.GetUsersByIds(userIDs, options)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
|
@ -1725,6 +1725,13 @@ func TestGetUsersByIds(t *testing.T) {
|
||||
|
||||
require.Len(t, users, 1, "1 user should be returned")
|
||||
})
|
||||
|
||||
t.Run("should only return unique users when multiple IDs are requested", func(t *testing.T) {
|
||||
users, _, err := client.GetUsersByIds(context.Background(), []string{th.BasicUser.Id, th.BasicUser.Id, th.BasicUser.Id})
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, users, 1, "1 user should be returned")
|
||||
})
|
||||
})
|
||||
|
||||
t.Run("should return error when not logged in", func(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user