[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
This commit is contained in:
Bolarinwa Balogun
2019-06-11 07:29:58 -04:00
committed by George Goldberg
parent c243b6640c
commit 3b03c9afcb
4 changed files with 23 additions and 20 deletions

View File

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

View File

@@ -357,16 +357,14 @@ func (s SqlTeamStore) SearchPrivate(term string) store.StoreChannel {
})
}
func (s SqlTeamStore) GetAll() store.StoreChannel {
return store.Do(func(result *store.StoreResult) {
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
}
func (s SqlTeamStore) GetAll() ([]*model.Team, *model.AppError) {
var teams []*model.Team
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 {

View File

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

View File

@@ -108,19 +108,28 @@ func (_m *TeamStore) GetActiveMemberCount(teamId string) store.StoreChannel {
}
// 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()
var r0 store.StoreChannel
if rf, ok := ret.Get(0).(func() store.StoreChannel); ok {
var r0 []*model.Team
if rf, ok := ret.Get(0).(func() []*model.Team); ok {
r0 = rf()
} else {
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