diff --git a/app/status.go b/app/status.go index 540b5ac075..f594ee9c4f 100644 --- a/app/status.go +++ b/app/status.go @@ -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) diff --git a/store/sqlstore/status_store.go b/store/sqlstore/status_store.go index d8926d6e53..de81e58bdc 100644 --- a/store/sqlstore/status_store.go +++ b/store/sqlstore/status_store.go @@ -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 { diff --git a/store/store.go b/store/store.go index b018a0d349..af90f00836 100644 --- a/store/store.go +++ b/store/store.go @@ -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) diff --git a/store/storetest/mocks/StatusStore.go b/store/storetest/mocks/StatusStore.go index f1945afc56..f84b9ceda0 100644 --- a/store/storetest/mocks/StatusStore.go +++ b/store/storetest/mocks/StatusStore.go @@ -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: diff --git a/store/storetest/status_store.go b/store/storetest/status_store.go index 7a3e5a3c5a..74f59e52e4 100644 --- a/store/storetest/status_store.go +++ b/store/storetest/status_store.go @@ -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") }