Migrate User.GetProfilesInChannelByStatus to Sync by default #11461 (#11623)

* Migrate User.GetProfilesInChannelByStatus to Sync by default #11461

* Refactor review changes #11461

* Refactor review changes #11461

* Refactor review changes #11461
Этот коммит содержится в:
Taufiq Rahman
2019-07-19 13:36:00 +06:00
коммит произвёл Jesús Espino
родитель 2bbfb1026d
Коммит 4b71ee6fe3
5 изменённых файлов: 48 добавлений и 47 удалений

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

@@ -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) {