mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Migrate "Status.GetByIds" to Sync by default (#11364)
* Migrate Status.GetByIds to Sync by default * gofmt the files
This commit is contained in:
committed by
Dean Whillier
parent
b68194e035
commit
1f6aedcdf3
@@ -78,11 +78,10 @@ func (a *App) GetStatusesByIds(userIds []string) (map[string]interface{}, *model
|
||||
}
|
||||
|
||||
if len(missingUserIds) > 0 {
|
||||
result := <-a.Srv.Store.Status().GetByIds(missingUserIds)
|
||||
if result.Err != nil {
|
||||
return nil, result.Err
|
||||
statuses, err := a.Srv.Store.Status().GetByIds(missingUserIds)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
statuses := result.Data.([]*model.Status)
|
||||
|
||||
for _, s := range statuses {
|
||||
a.AddStatusCacheSkipClusterSend(s)
|
||||
@@ -126,11 +125,10 @@ func (a *App) GetUserStatusesByIds(userIds []string) ([]*model.Status, *model.Ap
|
||||
}
|
||||
|
||||
if len(missingUserIds) > 0 {
|
||||
result := <-a.Srv.Store.Status().GetByIds(missingUserIds)
|
||||
if result.Err != nil {
|
||||
return nil, result.Err
|
||||
statuses, err := a.Srv.Store.Status().GetByIds(missingUserIds)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
statuses := result.Data.([]*model.Status)
|
||||
|
||||
for _, s := range statuses {
|
||||
a.AddStatusCacheSkipClusterSend(s)
|
||||
|
||||
@@ -76,27 +76,24 @@ func (s SqlStatusStore) Get(userId string) store.StoreChannel {
|
||||
})
|
||||
}
|
||||
|
||||
func (s SqlStatusStore) GetByIds(userIds []string) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
props := make(map[string]interface{})
|
||||
idQuery := ""
|
||||
func (s SqlStatusStore) GetByIds(userIds []string) ([]*model.Status, *model.AppError) {
|
||||
props := make(map[string]interface{})
|
||||
idQuery := ""
|
||||
|
||||
for index, userId := range userIds {
|
||||
if len(idQuery) > 0 {
|
||||
idQuery += ", "
|
||||
}
|
||||
|
||||
props["userId"+strconv.Itoa(index)] = userId
|
||||
idQuery += ":userId" + strconv.Itoa(index)
|
||||
for index, userId := range userIds {
|
||||
if len(idQuery) > 0 {
|
||||
idQuery += ", "
|
||||
}
|
||||
|
||||
var statuses []*model.Status
|
||||
if _, err := s.GetReplica().Select(&statuses, "SELECT * FROM Status WHERE UserId IN ("+idQuery+")", props); err != nil {
|
||||
result.Err = model.NewAppError("SqlStatusStore.GetByIds", "store.sql_status.get.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
} else {
|
||||
result.Data = statuses
|
||||
}
|
||||
})
|
||||
props["userId"+strconv.Itoa(index)] = userId
|
||||
idQuery += ":userId" + strconv.Itoa(index)
|
||||
}
|
||||
|
||||
var statuses []*model.Status
|
||||
if _, err := s.GetReplica().Select(&statuses, "SELECT * FROM Status WHERE UserId IN ("+idQuery+")", props); err != nil {
|
||||
return nil, model.NewAppError("SqlStatusStore.GetByIds", "store.sql_status.get.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
return statuses, nil
|
||||
}
|
||||
|
||||
func (s SqlStatusStore) GetOnlineAway() store.StoreChannel {
|
||||
|
||||
@@ -469,7 +469,7 @@ type EmojiStore interface {
|
||||
type StatusStore interface {
|
||||
SaveOrUpdate(status *model.Status) *model.AppError
|
||||
Get(userId string) StoreChannel
|
||||
GetByIds(userIds []string) StoreChannel
|
||||
GetByIds(userIds []string) ([]*model.Status, *model.AppError)
|
||||
GetOnlineAway() StoreChannel
|
||||
GetOnline() ([]*model.Status, *model.AppError)
|
||||
GetAllFromTeam(teamId string) ([]*model.Status, *model.AppError)
|
||||
|
||||
@@ -55,19 +55,28 @@ func (_m *StatusStore) GetAllFromTeam(teamId string) ([]*model.Status, *model.Ap
|
||||
}
|
||||
|
||||
// GetByIds provides a mock function with given fields: userIds
|
||||
func (_m *StatusStore) GetByIds(userIds []string) store.StoreChannel {
|
||||
func (_m *StatusStore) GetByIds(userIds []string) ([]*model.Status, *model.AppError) {
|
||||
ret := _m.Called(userIds)
|
||||
|
||||
var r0 store.StoreChannel
|
||||
if rf, ok := ret.Get(0).(func([]string) store.StoreChannel); ok {
|
||||
var r0 []*model.Status
|
||||
if rf, ok := ret.Get(0).(func([]string) []*model.Status); ok {
|
||||
r0 = rf(userIds)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(store.StoreChannel)
|
||||
r0 = ret.Get(0).([]*model.Status)
|
||||
}
|
||||
}
|
||||
|
||||
return r0
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func([]string) *model.AppError); ok {
|
||||
r1 = rf(userIds)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
}
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetOnline provides a mock function with given fields:
|
||||
|
||||
@@ -57,10 +57,9 @@ func testStatusStore(t *testing.T, ss store.Store) {
|
||||
}
|
||||
}
|
||||
|
||||
if result := <-ss.Status().GetByIds([]string{status.UserId, "junk"}); result.Err != nil {
|
||||
t.Fatal(result.Err)
|
||||
if statuses, err := ss.Status().GetByIds([]string{status.UserId, "junk"}); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
statuses := result.Data.([]*model.Status)
|
||||
if len(statuses) != 1 {
|
||||
t.Fatal("should only have 1 status")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user