MM-16579 Migrate User.GetChannelGroupUsers to Sync by default (#11412)

* Migrate User.GetChannelGroupUsers to Sync by default

* Directly return Store results
Этот коммит содержится в:
Claudio Costa
2019-06-26 18:42:21 +02:00
коммит произвёл Jesús Espino
родитель cb7c549c7b
Коммит 44b9fe3110
5 изменённых файлов: 32 добавлений и 32 удалений

Просмотреть файл

@@ -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. // GetChannelGroupUsers returns the users who are associated to the channel via GroupChannels and GroupMembers.
func (a *App) GetChannelGroupUsers(channelID string) ([]*model.User, *model.AppError) { func (a *App) GetChannelGroupUsers(channelID string) ([]*model.User, *model.AppError) {
result := <-a.Srv.Store.User().GetChannelGroupUsers(channelID) return a.Srv.Store.User().GetChannelGroupUsers(channelID)
if result.Err != nil {
return nil, result.Err
}
return result.Data.([]*model.User), nil
} }
func (a *App) GetUsersByIds(userIds []string, asAdmin bool, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError) { 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 { func (us SqlUserStore) GetChannelGroupUsers(channelID string) ([]*model.User, *model.AppError) {
return store.Do(func(result *store.StoreResult) { query := applyChannelGroupConstrainedFilter(us.usersQuery, channelID)
query := applyChannelGroupConstrainedFilter(us.usersQuery, channelID)
queryString, args, err := query.ToSql() queryString, args, err := query.ToSql()
if err != nil { if err != nil {
result.Err = model.NewAppError("SqlUserStore.GetChannelGroupUsers", "store.sql_user.app_error", nil, err.Error(), http.StatusInternalServerError) return nil, model.NewAppError("SqlUserStore.GetChannelGroupUsers", "store.sql_user.app_error", nil, err.Error(), http.StatusInternalServerError)
return }
}
var users []*model.User var users []*model.User
if _, err := us.GetReplica().Select(&users, queryString, args...); err != nil { 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 nil, model.NewAppError("SqlUserStore.GetChannelGroupUsers", "store.sql_user.get_profiles.app_error", nil, err.Error(), http.StatusInternalServerError)
return }
}
for _, u := range users { for _, u := range users {
u.Sanitize(map[string]bool{}) u.Sanitize(map[string]bool{})
} }
result.Data = users return users, nil
})
} }
func applyViewRestrictionsFilter(query sq.SelectBuilder, restrictions *model.ViewUsersRestrictions, distinct bool) sq.SelectBuilder { 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) GetUsersBatchForIndexing(startTime, endTime int64, limit int) ([]*model.UserForIndexing, *model.AppError)
Count(options model.UserCountOptions) (int64, *model.AppError) Count(options model.UserCountOptions) (int64, *model.AppError)
GetTeamGroupUsers(teamID string) StoreChannel GetTeamGroupUsers(teamID string) StoreChannel
GetChannelGroupUsers(channelID string) StoreChannel GetChannelGroupUsers(channelID string) ([]*model.User, *model.AppError)
} }
type BotStore interface { type BotStore interface {

Просмотреть файл

@@ -309,19 +309,28 @@ func (_m *UserStore) GetByUsername(username string) store.StoreChannel {
} }
// GetChannelGroupUsers provides a mock function with given fields: channelID // 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) ret := _m.Called(channelID)
var r0 store.StoreChannel var r0 []*model.User
if rf, ok := ret.Get(0).(func(string) store.StoreChannel); ok { if rf, ok := ret.Get(0).(func(string) []*model.User); ok {
r0 = rf(channelID) r0 = rf(channelID)
} else { } else {
if ret.Get(0) != nil { 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: // GetEtagForAllProfiles provides a mock function with given fields:

Просмотреть файл

@@ -3899,9 +3899,8 @@ func testUserStoreGetChannelGroupUsers(t *testing.T, ss store.Store) {
var users []*model.User var users []*model.User
requireNUsers := func(n int) { requireNUsers := func(n int) {
res = <-ss.User().GetChannelGroupUsers(channel.Id) users, err = ss.User().GetChannelGroupUsers(channel.Id)
require.Nil(t, res.Err) require.Nil(t, err)
users = res.Data.([]*model.User)
require.NotNil(t, users) require.NotNil(t, users)
require.Len(t, users, n) require.Len(t, users, n)
} }