* Migrate User.GetProfilesInChannelByStatus to Sync by default #11461 * Refactor review changes #11461 * Refactor review changes #11461 * Refactor review changes #11461
Этот коммит содержится в:
коммит произвёл
Jesús Espino
родитель
2bbfb1026d
Коммит
4b71ee6fe3
@@ -505,11 +505,7 @@ func (a *App) GetUsersInChannel(channelId string, offset int, limit int) ([]*mod
|
||||
}
|
||||
|
||||
func (a *App) GetUsersInChannelByStatus(channelId string, offset int, limit int) ([]*model.User, *model.AppError) {
|
||||
result := <-a.Srv.Store.User().GetProfilesInChannelByStatus(channelId, offset, limit)
|
||||
if result.Err != nil {
|
||||
return nil, result.Err
|
||||
}
|
||||
return result.Data.([]*model.User), nil
|
||||
return a.Srv.Store.User().GetProfilesInChannelByStatus(channelId, offset, limit)
|
||||
}
|
||||
|
||||
func (a *App) GetUsersInChannelMap(channelId string, offset int, limit int, asAdmin bool) (map[string]*model.User, *model.AppError) {
|
||||
|
||||
@@ -557,41 +557,37 @@ func (us SqlUserStore) GetProfilesInChannel(channelId string, offset int, limit
|
||||
})
|
||||
}
|
||||
|
||||
func (us SqlUserStore) GetProfilesInChannelByStatus(channelId string, offset int, limit int) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
query := us.usersQuery.
|
||||
Join("ChannelMembers cm ON ( cm.UserId = u.Id )").
|
||||
LeftJoin("Status s ON ( s.UserId = u.Id )").
|
||||
Where("cm.ChannelId = ?", channelId).
|
||||
OrderBy(`
|
||||
CASE s.Status
|
||||
WHEN 'online' THEN 1
|
||||
WHEN 'away' THEN 2
|
||||
WHEN 'dnd' THEN 3
|
||||
ELSE 4
|
||||
END
|
||||
func (us SqlUserStore) GetProfilesInChannelByStatus(channelId string, offset int, limit int) ([]*model.User, *model.AppError) {
|
||||
query := us.usersQuery.
|
||||
Join("ChannelMembers cm ON ( cm.UserId = u.Id )").
|
||||
LeftJoin("Status s ON ( s.UserId = u.Id )").
|
||||
Where("cm.ChannelId = ?", channelId).
|
||||
OrderBy(`
|
||||
CASE s.Status
|
||||
WHEN 'online' THEN 1
|
||||
WHEN 'away' THEN 2
|
||||
WHEN 'dnd' THEN 3
|
||||
ELSE 4
|
||||
END
|
||||
`).
|
||||
OrderBy("u.Username ASC").
|
||||
Offset(uint64(offset)).Limit(uint64(limit))
|
||||
OrderBy("u.Username ASC").
|
||||
Offset(uint64(offset)).Limit(uint64(limit))
|
||||
|
||||
queryString, args, err := query.ToSql()
|
||||
if err != nil {
|
||||
result.Err = model.NewAppError("SqlUserStore.GetProfilesInChannelByStatus", "store.sql_user.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
queryString, args, err := query.ToSql()
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("SqlUserStore.GetProfilesInChannelByStatus", "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.GetProfilesInChannelByStatus", "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.GetProfilesInChannelByStatus", "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 (us SqlUserStore) GetAllProfilesInChannel(channelId string, allowFromCache bool) (map[string]*model.User, *model.AppError) {
|
||||
|
||||
@@ -264,7 +264,7 @@ type UserStore interface {
|
||||
InvalidateProfilesInChannelCacheByUser(userId string)
|
||||
InvalidateProfilesInChannelCache(channelId string)
|
||||
GetProfilesInChannel(channelId string, offset int, limit int) StoreChannel
|
||||
GetProfilesInChannelByStatus(channelId string, offset int, limit int) StoreChannel
|
||||
GetProfilesInChannelByStatus(channelId string, offset int, limit int) ([]*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)
|
||||
GetProfilesWithoutTeam(offset int, limit int, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError)
|
||||
|
||||
@@ -608,19 +608,28 @@ func (_m *UserStore) GetProfilesInChannel(channelId string, offset int, limit in
|
||||
}
|
||||
|
||||
// GetProfilesInChannelByStatus provides a mock function with given fields: channelId, offset, limit
|
||||
func (_m *UserStore) GetProfilesInChannelByStatus(channelId string, offset int, limit int) store.StoreChannel {
|
||||
func (_m *UserStore) GetProfilesInChannelByStatus(channelId string, offset int, limit int) ([]*model.User, *model.AppError) {
|
||||
ret := _m.Called(channelId, offset, limit)
|
||||
|
||||
var r0 store.StoreChannel
|
||||
if rf, ok := ret.Get(0).(func(string, int, int) store.StoreChannel); ok {
|
||||
var r0 []*model.User
|
||||
if rf, ok := ret.Get(0).(func(string, int, int) []*model.User); ok {
|
||||
r0 = rf(channelId, offset, limit)
|
||||
} 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, 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
|
||||
}
|
||||
|
||||
// GetProfilesNotInChannel provides a mock function with given fields: teamId, channelId, groupConstrained, offset, limit, viewRestrictions
|
||||
|
||||
@@ -846,15 +846,15 @@ func testUserStoreGetProfilesInChannelByStatus(t *testing.T, ss store.Store) {
|
||||
}))
|
||||
|
||||
t.Run("get in channel 1 by status, offset 0, limit 100", func(t *testing.T) {
|
||||
result := <-ss.User().GetProfilesInChannelByStatus(c1.Id, 0, 100)
|
||||
require.Nil(t, result.Err)
|
||||
assert.Equal(t, []*model.User{sanitized(u3), sanitized(u2), sanitized(u1)}, result.Data.([]*model.User))
|
||||
users, err := ss.User().GetProfilesInChannelByStatus(c1.Id, 0, 100)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, []*model.User{sanitized(u3), sanitized(u2), sanitized(u1)}, users)
|
||||
})
|
||||
|
||||
t.Run("get in channel 2 by status, offset 0, limit 1", func(t *testing.T) {
|
||||
result := <-ss.User().GetProfilesInChannelByStatus(c2.Id, 0, 1)
|
||||
require.Nil(t, result.Err)
|
||||
assert.Equal(t, []*model.User{sanitized(u1)}, result.Data.([]*model.User))
|
||||
users, err := ss.User().GetProfilesInChannelByStatus(c2.Id, 0, 1)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, []*model.User{sanitized(u1)}, users)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user