mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
MM-16579 Migrate User.GetChannelGroupUsers to Sync by default (#11412)
* Migrate User.GetChannelGroupUsers to Sync by default * Directly return Store results
This commit is contained in:
committed by
Jesús Espino
parent
cb7c549c7b
commit
44b9fe3110
@@ -618,11 +618,7 @@ func (a *App) GetTeamGroupUsers(teamID string) ([]*model.User, *model.AppError)
|
||||
|
||||
// GetChannelGroupUsers returns the users who are associated to the channel via GroupChannels and GroupMembers.
|
||||
func (a *App) GetChannelGroupUsers(channelID string) ([]*model.User, *model.AppError) {
|
||||
result := <-a.Srv.Store.User().GetChannelGroupUsers(channelID)
|
||||
if result.Err != nil {
|
||||
return nil, result.Err
|
||||
}
|
||||
return result.Data.([]*model.User), nil
|
||||
return a.Srv.Store.User().GetChannelGroupUsers(channelID)
|
||||
}
|
||||
|
||||
func (a *App) GetUsersByIds(userIds []string, asAdmin bool, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError) {
|
||||
|
||||
@@ -1671,28 +1671,24 @@ func (us SqlUserStore) GetTeamGroupUsers(teamID string) store.StoreChannel {
|
||||
})
|
||||
}
|
||||
|
||||
func (us SqlUserStore) GetChannelGroupUsers(channelID string) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
query := applyChannelGroupConstrainedFilter(us.usersQuery, channelID)
|
||||
func (us SqlUserStore) GetChannelGroupUsers(channelID string) ([]*model.User, *model.AppError) {
|
||||
query := applyChannelGroupConstrainedFilter(us.usersQuery, channelID)
|
||||
|
||||
queryString, args, err := query.ToSql()
|
||||
if err != nil {
|
||||
result.Err = model.NewAppError("SqlUserStore.GetChannelGroupUsers", "store.sql_user.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
queryString, args, err := query.ToSql()
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("SqlUserStore.GetChannelGroupUsers", "store.sql_user.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
var users []*model.User
|
||||
if _, err := us.GetReplica().Select(&users, queryString, args...); err != nil {
|
||||
result.Err = model.NewAppError("SqlUserStore.GetChannelGroupUsers", "store.sql_user.get_profiles.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
var users []*model.User
|
||||
if _, err := us.GetReplica().Select(&users, queryString, args...); err != nil {
|
||||
return nil, model.NewAppError("SqlUserStore.GetChannelGroupUsers", "store.sql_user.get_profiles.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
for _, u := range users {
|
||||
u.Sanitize(map[string]bool{})
|
||||
}
|
||||
for _, u := range users {
|
||||
u.Sanitize(map[string]bool{})
|
||||
}
|
||||
|
||||
result.Data = users
|
||||
})
|
||||
return users, nil
|
||||
}
|
||||
|
||||
func applyViewRestrictionsFilter(query sq.SelectBuilder, restrictions *model.ViewUsersRestrictions, distinct bool) sq.SelectBuilder {
|
||||
|
||||
@@ -303,7 +303,7 @@ type UserStore interface {
|
||||
GetUsersBatchForIndexing(startTime, endTime int64, limit int) ([]*model.UserForIndexing, *model.AppError)
|
||||
Count(options model.UserCountOptions) (int64, *model.AppError)
|
||||
GetTeamGroupUsers(teamID string) StoreChannel
|
||||
GetChannelGroupUsers(channelID string) StoreChannel
|
||||
GetChannelGroupUsers(channelID string) ([]*model.User, *model.AppError)
|
||||
}
|
||||
|
||||
type BotStore interface {
|
||||
|
||||
@@ -309,19 +309,28 @@ func (_m *UserStore) GetByUsername(username string) store.StoreChannel {
|
||||
}
|
||||
|
||||
// GetChannelGroupUsers provides a mock function with given fields: channelID
|
||||
func (_m *UserStore) GetChannelGroupUsers(channelID string) store.StoreChannel {
|
||||
func (_m *UserStore) GetChannelGroupUsers(channelID string) ([]*model.User, *model.AppError) {
|
||||
ret := _m.Called(channelID)
|
||||
|
||||
var r0 store.StoreChannel
|
||||
if rf, ok := ret.Get(0).(func(string) store.StoreChannel); ok {
|
||||
var r0 []*model.User
|
||||
if rf, ok := ret.Get(0).(func(string) []*model.User); ok {
|
||||
r0 = rf(channelID)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(store.StoreChannel)
|
||||
r0 = ret.Get(0).([]*model.User)
|
||||
}
|
||||
}
|
||||
|
||||
return r0
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(string) *model.AppError); ok {
|
||||
r1 = rf(channelID)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
}
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetEtagForAllProfiles provides a mock function with given fields:
|
||||
|
||||
@@ -3899,9 +3899,8 @@ func testUserStoreGetChannelGroupUsers(t *testing.T, ss store.Store) {
|
||||
var users []*model.User
|
||||
|
||||
requireNUsers := func(n int) {
|
||||
res = <-ss.User().GetChannelGroupUsers(channel.Id)
|
||||
require.Nil(t, res.Err)
|
||||
users = res.Data.([]*model.User)
|
||||
users, err = ss.User().GetChannelGroupUsers(channel.Id)
|
||||
require.Nil(t, err)
|
||||
require.NotNil(t, users)
|
||||
require.Len(t, users, n)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user