[MM-16658] Migrate User.GetProfilesInChannel to Sync by default #11462 (#11685)

* Migrate User.GetProfilesInChannel to Sync by default #11462

* Refactor variable names #11462
Этот коммит содержится в:
Taufiq Rahman
2019-07-26 17:11:13 +06:00
коммит произвёл Jesús Espino
родитель 447589a06e
Коммит 7e092886dc
5 изменённых файлов: 43 добавлений и 42 удалений

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

@@ -516,11 +516,7 @@ func (a *App) GetUsersNotInTeamEtag(teamId string, restrictionsHash string) stri
} }
func (a *App) GetUsersInChannel(channelId string, offset int, limit int) ([]*model.User, *model.AppError) { func (a *App) GetUsersInChannel(channelId string, offset int, limit int) ([]*model.User, *model.AppError) {
result := <-a.Srv.Store.User().GetProfilesInChannel(channelId, offset, limit) return a.Srv.Store.User().GetProfilesInChannel(channelId, offset, limit)
if result.Err != nil {
return nil, result.Err
}
return result.Data.([]*model.User), nil
} }
func (a *App) GetUsersInChannelByStatus(channelId string, offset int, limit int) ([]*model.User, *model.AppError) { func (a *App) GetUsersInChannelByStatus(channelId string, offset int, limit int) ([]*model.User, *model.AppError) {

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

@@ -529,32 +529,28 @@ func (us SqlUserStore) InvalidateProfilesInChannelCache(channelId string) {
} }
} }
func (us SqlUserStore) GetProfilesInChannel(channelId string, offset int, limit int) store.StoreChannel { func (us SqlUserStore) GetProfilesInChannel(channelId string, offset int, limit int) ([]*model.User, *model.AppError) {
return store.Do(func(result *store.StoreResult) { query := us.usersQuery.
query := us.usersQuery. Join("ChannelMembers cm ON ( cm.UserId = u.Id )").
Join("ChannelMembers cm ON ( cm.UserId = u.Id )"). Where("cm.ChannelId = ?", channelId).
Where("cm.ChannelId = ?", channelId). OrderBy("u.Username ASC").
OrderBy("u.Username ASC"). Offset(uint64(offset)).Limit(uint64(limit))
Offset(uint64(offset)).Limit(uint64(limit))
queryString, args, err := query.ToSql() queryString, args, err := query.ToSql()
if err != nil { if err != nil {
result.Err = model.NewAppError("SqlUserStore.GetProfilesInChannel", "store.sql_user.app_error", nil, err.Error(), http.StatusInternalServerError) return nil, model.NewAppError("SqlUserStore.GetProfilesInChannel", "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.GetProfilesInChannel", "store.sql_user.get_profiles.app_error", nil, err.Error(), http.StatusInternalServerError) return nil, model.NewAppError("SqlUserStore.GetProfilesInChannel", "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 (us SqlUserStore) GetProfilesInChannelByStatus(channelId string, offset int, limit int) ([]*model.User, *model.AppError) { func (us SqlUserStore) GetProfilesInChannelByStatus(channelId string, offset int, limit int) ([]*model.User, *model.AppError) {

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

@@ -266,7 +266,7 @@ type UserStore interface {
ClearCaches() ClearCaches()
InvalidateProfilesInChannelCacheByUser(userId string) InvalidateProfilesInChannelCacheByUser(userId string)
InvalidateProfilesInChannelCache(channelId string) InvalidateProfilesInChannelCache(channelId string)
GetProfilesInChannel(channelId string, offset int, limit int) StoreChannel GetProfilesInChannel(channelId string, offset int, limit int) ([]*model.User, *model.AppError)
GetProfilesInChannelByStatus(channelId string, offset int, limit int) ([]*model.User, *model.AppError) GetProfilesInChannelByStatus(channelId string, offset int, limit int) ([]*model.User, *model.AppError)
GetAllProfilesInChannel(channelId string, allowFromCache bool) (map[string]*model.User, *model.AppError) GetAllProfilesInChannel(channelId string, allowFromCache bool) (map[string]*model.User, *model.AppError)
GetProfilesNotInChannel(teamId string, channelId string, groupConstrained bool, offset int, limit int, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError) GetProfilesNotInChannel(teamId string, channelId string, groupConstrained bool, offset int, limit int, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError)

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

@@ -608,19 +608,28 @@ func (_m *UserStore) GetProfilesByUsernames(usernames []string, viewRestrictions
} }
// GetProfilesInChannel provides a mock function with given fields: channelId, offset, limit // GetProfilesInChannel provides a mock function with given fields: channelId, offset, limit
func (_m *UserStore) GetProfilesInChannel(channelId string, offset int, limit int) store.StoreChannel { func (_m *UserStore) GetProfilesInChannel(channelId string, offset int, limit int) ([]*model.User, *model.AppError) {
ret := _m.Called(channelId, offset, limit) ret := _m.Called(channelId, offset, limit)
var r0 store.StoreChannel var r0 []*model.User
if rf, ok := ret.Get(0).(func(string, int, int) store.StoreChannel); ok { if rf, ok := ret.Get(0).(func(string, int, int) []*model.User); ok {
r0 = rf(channelId, offset, limit) r0 = rf(channelId, offset, limit)
} 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, int, int) *model.AppError); ok {
r1 = rf(channelId, offset, limit)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
}
return r0, r1
} }
// GetProfilesInChannelByStatus provides a mock function with given fields: channelId, offset, limit // GetProfilesInChannelByStatus provides a mock function with given fields: channelId, offset, limit

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

@@ -747,21 +747,21 @@ func testUserStoreGetProfilesInChannel(t *testing.T, ss store.Store) {
}) })
require.Nil(t, err) require.Nil(t, err)
t.Run("get in channel 1, offset 0, limit 100", func(t *testing.T) { t.Run("get in channel 1, offset 0, limit 100", func(t *testing.T) {
result := <-ss.User().GetProfilesInChannel(c1.Id, 0, 100) users, err := ss.User().GetProfilesInChannel(c1.Id, 0, 100)
require.Nil(t, result.Err) require.Nil(t, err)
assert.Equal(t, []*model.User{sanitized(u1), sanitized(u2), sanitized(u3)}, result.Data.([]*model.User)) assert.Equal(t, []*model.User{sanitized(u1), sanitized(u2), sanitized(u3)}, users)
}) })
t.Run("get in channel 1, offset 1, limit 2", func(t *testing.T) { t.Run("get in channel 1, offset 1, limit 2", func(t *testing.T) {
result := <-ss.User().GetProfilesInChannel(c1.Id, 1, 2) users, err := ss.User().GetProfilesInChannel(c1.Id, 1, 2)
require.Nil(t, result.Err) require.Nil(t, err)
assert.Equal(t, []*model.User{sanitized(u2), sanitized(u3)}, result.Data.([]*model.User)) assert.Equal(t, []*model.User{sanitized(u2), sanitized(u3)}, users)
}) })
t.Run("get in channel 2, offset 0, limit 1", func(t *testing.T) { t.Run("get in channel 2, offset 0, limit 1", func(t *testing.T) {
result := <-ss.User().GetProfilesInChannel(c2.Id, 0, 1) users, err := ss.User().GetProfilesInChannel(c2.Id, 0, 1)
require.Nil(t, result.Err) require.Nil(t, err)
assert.Equal(t, []*model.User{sanitized(u1)}, result.Data.([]*model.User)) assert.Equal(t, []*model.User{sanitized(u1)}, users)
}) })
} }