From 6fc0ec06b260b9dff721c05b9e1601a505ced2ed Mon Sep 17 00:00:00 2001 From: Mounica Paladugu <49451510+mounicapaladugu@users.noreply.github.com> Date: Tue, 9 Jul 2019 08:19:18 -0700 Subject: [PATCH] [MM-16168] Migrate Team.GetAllTeamListing to Sync by default (#11102) * [MM-16168] Migrate Team.GetAllTeamListing to Sync by default * reverting GetAllTeamPageListing modification * Modifying app/team.go * Simplifying code --- app/team.go | 6 +----- store/sqlstore/team_store.go | 23 ++++++++++------------- store/store.go | 2 +- store/storetest/mocks/TeamStore.go | 19 ++++++++++++++----- store/storetest/team_store.go | 6 ++---- 5 files changed, 28 insertions(+), 28 deletions(-) diff --git a/app/team.go b/app/team.go index 7b5fddbc52..a654d8413e 100644 --- a/app/team.go +++ b/app/team.go @@ -634,11 +634,7 @@ func (a *App) GetAllPrivateTeamsPage(offset int, limit int) ([]*model.Team, *mod } func (a *App) GetAllPublicTeams() ([]*model.Team, *model.AppError) { - result := <-a.Srv.Store.Team().GetAllTeamListing() - if result.Err != nil { - return nil, result.Err - } - return result.Data.([]*model.Team), nil + return a.Srv.Store.Team().GetAllTeamListing() } func (a *App) GetAllPublicTeamsPage(offset int, limit int) ([]*model.Team, *model.AppError) { diff --git a/store/sqlstore/team_store.go b/store/sqlstore/team_store.go index 2e8e6c36e8..f8249b7aab 100644 --- a/store/sqlstore/team_store.go +++ b/store/sqlstore/team_store.go @@ -418,22 +418,19 @@ func (s SqlTeamStore) GetAllPrivateTeamPageListing(offset int, limit int) ([]*mo return data, nil } -func (s SqlTeamStore) GetAllTeamListing() store.StoreChannel { - return store.Do(func(result *store.StoreResult) { - query := "SELECT * FROM Teams WHERE AllowOpenInvite = 1 ORDER BY DisplayName" +func (s SqlTeamStore) GetAllTeamListing() ([]*model.Team, *model.AppError) { + query := "SELECT * FROM Teams WHERE AllowOpenInvite = 1 ORDER BY DisplayName" - if s.DriverName() == model.DATABASE_DRIVER_POSTGRES { - query = "SELECT * FROM Teams WHERE AllowOpenInvite = true ORDER BY DisplayName" - } + if s.DriverName() == model.DATABASE_DRIVER_POSTGRES { + query = "SELECT * FROM Teams WHERE AllowOpenInvite = true ORDER BY DisplayName" + } - var data []*model.Team - if _, err := s.GetReplica().Select(&data, query); err != nil { - result.Err = model.NewAppError("SqlTeamStore.GetAllTeamListing", "store.sql_team.get_all_team_listing.app_error", nil, err.Error(), http.StatusInternalServerError) - return - } + var data []*model.Team + if _, err := s.GetReplica().Select(&data, query); err != nil { + return nil, model.NewAppError("SqlTeamStore.GetAllTeamListing", "store.sql_team.get_all_team_listing.app_error", nil, err.Error(), http.StatusInternalServerError) + } - result.Data = data - }) + return data, nil } func (s SqlTeamStore) GetAllTeamPageListing(offset int, limit int) ([]*model.Team, *model.AppError) { diff --git a/store/store.go b/store/store.go index c8da9fddc2..f7796b6525 100644 --- a/store/store.go +++ b/store/store.go @@ -94,7 +94,7 @@ type TeamStore interface { GetAllPage(offset int, limit int) ([]*model.Team, *model.AppError) GetAllPrivateTeamListing() ([]*model.Team, *model.AppError) GetAllPrivateTeamPageListing(offset int, limit int) ([]*model.Team, *model.AppError) - GetAllTeamListing() StoreChannel + GetAllTeamListing() ([]*model.Team, *model.AppError) GetAllTeamPageListing(offset int, limit int) ([]*model.Team, *model.AppError) GetTeamsByUserId(userId string) StoreChannel GetByInviteId(inviteId string) (*model.Team, *model.AppError) diff --git a/store/storetest/mocks/TeamStore.go b/store/storetest/mocks/TeamStore.go index c9f5ebe38e..2ccc85b893 100644 --- a/store/storetest/mocks/TeamStore.go +++ b/store/storetest/mocks/TeamStore.go @@ -247,19 +247,28 @@ func (_m *TeamStore) GetAllPrivateTeamPageListing(offset int, limit int) ([]*mod } // GetAllTeamListing provides a mock function with given fields: -func (_m *TeamStore) GetAllTeamListing() store.StoreChannel { +func (_m *TeamStore) GetAllTeamListing() ([]*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 } // GetAllTeamPageListing provides a mock function with given fields: offset, limit diff --git a/store/storetest/team_store.go b/store/storetest/team_store.go index e8d12eb3fe..f34f054e9f 100644 --- a/store/storetest/team_store.go +++ b/store/storetest/team_store.go @@ -481,11 +481,9 @@ func testGetAllTeamListing(t *testing.T, ss store.Store) { _, err = ss.Team().Save(&o4) require.Nil(t, err) - if r1 := <-ss.Team().GetAllTeamListing(); r1.Err != nil { - t.Fatal(r1.Err) + if teams, err := ss.Team().GetAllTeamListing(); err != nil { + t.Fatal(err) } else { - teams := r1.Data.([]*model.Team) - for _, team := range teams { if !team.AllowOpenInvite { t.Fatal("should have returned team with AllowOpenInvite as true")