[MM-16164] Migrate "Team.GetAll" to Sync by default (#11108)

* [MM-16164] Migrate "Team.GetAll" to Sync by default

* Refactor to make code shorter and more descriptive
Этот коммит содержится в:
Bolarinwa Balogun
2019-06-11 07:29:58 -04:00
коммит произвёл George Goldberg
родитель c243b6640c
Коммит 3b03c9afcb
4 изменённых файлов: 23 добавлений и 20 удалений

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

@@ -609,11 +609,7 @@ func (a *App) GetTeamByInviteId(inviteId string) (*model.Team, *model.AppError)
} }
func (a *App) GetAllTeams() ([]*model.Team, *model.AppError) { func (a *App) GetAllTeams() ([]*model.Team, *model.AppError) {
result := <-a.Srv.Store.Team().GetAll() return a.Srv.Store.Team().GetAll()
if result.Err != nil {
return nil, result.Err
}
return result.Data.([]*model.Team), nil
} }
func (a *App) GetAllTeamsPage(offset int, limit int) ([]*model.Team, *model.AppError) { func (a *App) GetAllTeamsPage(offset int, limit int) ([]*model.Team, *model.AppError) {

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

@@ -357,16 +357,14 @@ func (s SqlTeamStore) SearchPrivate(term string) store.StoreChannel {
}) })
} }
func (s SqlTeamStore) GetAll() store.StoreChannel { func (s SqlTeamStore) GetAll() ([]*model.Team, *model.AppError) {
return store.Do(func(result *store.StoreResult) { var teams []*model.Team
var data []*model.Team
if _, err := s.GetReplica().Select(&data, "SELECT * FROM Teams ORDER BY DisplayName"); err != nil {
result.Err = model.NewAppError("SqlTeamStore.GetAllTeams", "store.sql_team.get_all.app_error", nil, err.Error(), http.StatusInternalServerError)
return
}
result.Data = data _, err := s.GetReplica().Select(&teams, "SELECT * FROM Teams ORDER BY DisplayName")
}) if err != nil {
return nil, model.NewAppError("SqlTeamStore.GetAllTeams", "store.sql_team.get_all.app_error", nil, err.Error(), http.StatusInternalServerError)
}
return teams, nil
} }
func (s SqlTeamStore) GetAllPage(offset int, limit int) store.StoreChannel { func (s SqlTeamStore) GetAllPage(offset int, limit int) store.StoreChannel {

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

@@ -90,7 +90,7 @@ type TeamStore interface {
SearchAll(term string) StoreChannel SearchAll(term string) StoreChannel
SearchOpen(term string) StoreChannel SearchOpen(term string) StoreChannel
SearchPrivate(term string) StoreChannel SearchPrivate(term string) StoreChannel
GetAll() StoreChannel GetAll() ([]*model.Team, *model.AppError)
GetAllPage(offset int, limit int) StoreChannel GetAllPage(offset int, limit int) StoreChannel
GetAllPrivateTeamListing() StoreChannel GetAllPrivateTeamListing() StoreChannel
GetAllPrivateTeamPageListing(offset int, limit int) StoreChannel GetAllPrivateTeamPageListing(offset int, limit int) StoreChannel

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

@@ -108,19 +108,28 @@ func (_m *TeamStore) GetActiveMemberCount(teamId string) store.StoreChannel {
} }
// GetAll provides a mock function with given fields: // GetAll provides a mock function with given fields:
func (_m *TeamStore) GetAll() store.StoreChannel { func (_m *TeamStore) GetAll() ([]*model.Team, *model.AppError) {
ret := _m.Called() ret := _m.Called()
var r0 store.StoreChannel var r0 []*model.Team
if rf, ok := ret.Get(0).(func() store.StoreChannel); ok { if rf, ok := ret.Get(0).(func() []*model.Team); ok {
r0 = rf() r0 = rf()
} else { } else {
if ret.Get(0) != nil { if ret.Get(0) != nil {
r0 = ret.Get(0).(store.StoreChannel) r0 = ret.Get(0).([]*model.Team)
} }
} }
return r0 var r1 *model.AppError
if rf, ok := ret.Get(1).(func() *model.AppError); ok {
r1 = rf()
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
}
return r0, r1
} }
// GetAllForExportAfter provides a mock function with given fields: limit, afterId // GetAllForExportAfter provides a mock function with given fields: limit, afterId