Migrate "Status.GetByIds" to Sync by default (#11364)
* Migrate Status.GetByIds to Sync by default * gofmt the files
Этот коммит содержится в:
коммит произвёл
Dean Whillier
родитель
b68194e035
Коммит
1f6aedcdf3
@@ -78,11 +78,10 @@ func (a *App) GetStatusesByIds(userIds []string) (map[string]interface{}, *model
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(missingUserIds) > 0 {
|
if len(missingUserIds) > 0 {
|
||||||
result := <-a.Srv.Store.Status().GetByIds(missingUserIds)
|
statuses, err := a.Srv.Store.Status().GetByIds(missingUserIds)
|
||||||
if result.Err != nil {
|
if err != nil {
|
||||||
return nil, result.Err
|
return nil, err
|
||||||
}
|
}
|
||||||
statuses := result.Data.([]*model.Status)
|
|
||||||
|
|
||||||
for _, s := range statuses {
|
for _, s := range statuses {
|
||||||
a.AddStatusCacheSkipClusterSend(s)
|
a.AddStatusCacheSkipClusterSend(s)
|
||||||
@@ -126,11 +125,10 @@ func (a *App) GetUserStatusesByIds(userIds []string) ([]*model.Status, *model.Ap
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(missingUserIds) > 0 {
|
if len(missingUserIds) > 0 {
|
||||||
result := <-a.Srv.Store.Status().GetByIds(missingUserIds)
|
statuses, err := a.Srv.Store.Status().GetByIds(missingUserIds)
|
||||||
if result.Err != nil {
|
if err != nil {
|
||||||
return nil, result.Err
|
return nil, err
|
||||||
}
|
}
|
||||||
statuses := result.Data.([]*model.Status)
|
|
||||||
|
|
||||||
for _, s := range statuses {
|
for _, s := range statuses {
|
||||||
a.AddStatusCacheSkipClusterSend(s)
|
a.AddStatusCacheSkipClusterSend(s)
|
||||||
|
|||||||
@@ -76,27 +76,24 @@ func (s SqlStatusStore) Get(userId string) store.StoreChannel {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SqlStatusStore) GetByIds(userIds []string) store.StoreChannel {
|
func (s SqlStatusStore) GetByIds(userIds []string) ([]*model.Status, *model.AppError) {
|
||||||
return store.Do(func(result *store.StoreResult) {
|
props := make(map[string]interface{})
|
||||||
props := make(map[string]interface{})
|
idQuery := ""
|
||||||
idQuery := ""
|
|
||||||
|
|
||||||
for index, userId := range userIds {
|
for index, userId := range userIds {
|
||||||
if len(idQuery) > 0 {
|
if len(idQuery) > 0 {
|
||||||
idQuery += ", "
|
idQuery += ", "
|
||||||
}
|
|
||||||
|
|
||||||
props["userId"+strconv.Itoa(index)] = userId
|
|
||||||
idQuery += ":userId" + strconv.Itoa(index)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var statuses []*model.Status
|
props["userId"+strconv.Itoa(index)] = userId
|
||||||
if _, err := s.GetReplica().Select(&statuses, "SELECT * FROM Status WHERE UserId IN ("+idQuery+")", props); err != nil {
|
idQuery += ":userId" + strconv.Itoa(index)
|
||||||
result.Err = model.NewAppError("SqlStatusStore.GetByIds", "store.sql_status.get.app_error", nil, err.Error(), http.StatusInternalServerError)
|
}
|
||||||
} else {
|
|
||||||
result.Data = statuses
|
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 {
|
func (s SqlStatusStore) GetOnlineAway() store.StoreChannel {
|
||||||
|
|||||||
@@ -469,7 +469,7 @@ type EmojiStore interface {
|
|||||||
type StatusStore interface {
|
type StatusStore interface {
|
||||||
SaveOrUpdate(status *model.Status) *model.AppError
|
SaveOrUpdate(status *model.Status) *model.AppError
|
||||||
Get(userId string) StoreChannel
|
Get(userId string) StoreChannel
|
||||||
GetByIds(userIds []string) StoreChannel
|
GetByIds(userIds []string) ([]*model.Status, *model.AppError)
|
||||||
GetOnlineAway() StoreChannel
|
GetOnlineAway() StoreChannel
|
||||||
GetOnline() ([]*model.Status, *model.AppError)
|
GetOnline() ([]*model.Status, *model.AppError)
|
||||||
GetAllFromTeam(teamId string) ([]*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
|
// 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)
|
ret := _m.Called(userIds)
|
||||||
|
|
||||||
var r0 store.StoreChannel
|
var r0 []*model.Status
|
||||||
if rf, ok := ret.Get(0).(func([]string) store.StoreChannel); ok {
|
if rf, ok := ret.Get(0).(func([]string) []*model.Status); ok {
|
||||||
r0 = rf(userIds)
|
r0 = rf(userIds)
|
||||||
} else {
|
} else {
|
||||||
if ret.Get(0) != nil {
|
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:
|
// 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 {
|
if statuses, err := ss.Status().GetByIds([]string{status.UserId, "junk"}); err != nil {
|
||||||
t.Fatal(result.Err)
|
t.Fatal(err)
|
||||||
} else {
|
} else {
|
||||||
statuses := result.Data.([]*model.Status)
|
|
||||||
if len(statuses) != 1 {
|
if len(statuses) != 1 {
|
||||||
t.Fatal("should only have 1 status")
|
t.Fatal("should only have 1 status")
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user