From eddf48c8480bea4851fc5f28c5ad7776c1080e37 Mon Sep 17 00:00:00 2001 From: Mounica Paladugu <49451510+mounicapaladugu@users.noreply.github.com> Date: Mon, 8 Jul 2019 12:30:52 -0700 Subject: [PATCH] [MM-16166] Migrate Team.GetAllPrivateTeamListing to Sync by default (#11103) * [MM-16166] Migrate Team.GetAllPrivateTeamListing to Sync by default * 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 7622ef264a..51bfa3dc79 100644 --- a/app/team.go +++ b/app/team.go @@ -626,11 +626,7 @@ func (a *App) GetAllTeamsPageWithCount(offset int, limit int) (*model.TeamsWithC } func (a *App) GetAllPrivateTeams() ([]*model.Team, *model.AppError) { - result := <-a.Srv.Store.Team().GetAllPrivateTeamListing() - if result.Err != nil { - return nil, result.Err - } - return result.Data.([]*model.Team), nil + return a.Srv.Store.Team().GetAllPrivateTeamListing() } func (a *App) GetAllPrivateTeamsPage(offset int, limit int) ([]*model.Team, *model.AppError) { diff --git a/store/sqlstore/team_store.go b/store/sqlstore/team_store.go index a821e8db6e..49f86b1867 100644 --- a/store/sqlstore/team_store.go +++ b/store/sqlstore/team_store.go @@ -388,22 +388,19 @@ func (s SqlTeamStore) GetTeamsByUserId(userId string) store.StoreChannel { }) } -func (s SqlTeamStore) GetAllPrivateTeamListing() store.StoreChannel { - return store.Do(func(result *store.StoreResult) { - query := "SELECT * FROM Teams WHERE AllowOpenInvite = 0 ORDER BY DisplayName" +func (s SqlTeamStore) GetAllPrivateTeamListing() ([]*model.Team, *model.AppError) { + query := "SELECT * FROM Teams WHERE AllowOpenInvite = 0 ORDER BY DisplayName" - if s.DriverName() == model.DATABASE_DRIVER_POSTGRES { - query = "SELECT * FROM Teams WHERE AllowOpenInvite = false ORDER BY DisplayName" - } + if s.DriverName() == model.DATABASE_DRIVER_POSTGRES { + query = "SELECT * FROM Teams WHERE AllowOpenInvite = false ORDER BY DisplayName" + } - var data []*model.Team - if _, err := s.GetReplica().Select(&data, query); err != nil { - result.Err = model.NewAppError("SqlTeamStore.GetAllPrivateTeamListing", "store.sql_team.get_all_private_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.GetAllPrivateTeamListing", "store.sql_team.get_all_private_team_listing.app_error", nil, err.Error(), http.StatusInternalServerError) + } - result.Data = data - }) + return data, nil } func (s SqlTeamStore) GetAllPrivateTeamPageListing(offset int, limit int) ([]*model.Team, *model.AppError) { diff --git a/store/store.go b/store/store.go index 4d731397fd..6183079ef9 100644 --- a/store/store.go +++ b/store/store.go @@ -92,7 +92,7 @@ type TeamStore interface { SearchPrivate(term string) ([]*model.Team, *model.AppError) GetAll() ([]*model.Team, *model.AppError) GetAllPage(offset int, limit int) ([]*model.Team, *model.AppError) - GetAllPrivateTeamListing() StoreChannel + GetAllPrivateTeamListing() ([]*model.Team, *model.AppError) GetAllPrivateTeamPageListing(offset int, limit int) ([]*model.Team, *model.AppError) GetAllTeamListing() StoreChannel GetAllTeamPageListing(offset int, limit int) ([]*model.Team, *model.AppError) diff --git a/store/storetest/mocks/TeamStore.go b/store/storetest/mocks/TeamStore.go index 5abfd76992..0de134487d 100644 --- a/store/storetest/mocks/TeamStore.go +++ b/store/storetest/mocks/TeamStore.go @@ -197,19 +197,28 @@ func (_m *TeamStore) GetAllPage(offset int, limit int) ([]*model.Team, *model.Ap } // GetAllPrivateTeamListing provides a mock function with given fields: -func (_m *TeamStore) GetAllPrivateTeamListing() store.StoreChannel { +func (_m *TeamStore) GetAllPrivateTeamListing() ([]*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 } // GetAllPrivateTeamPageListing provides a mock function with given fields: offset, limit diff --git a/store/storetest/team_store.go b/store/storetest/team_store.go index 62d28b489b..fb2ee1620d 100644 --- a/store/storetest/team_store.go +++ b/store/storetest/team_store.go @@ -619,11 +619,9 @@ func testGetAllPrivateTeamListing(t *testing.T, ss store.Store) { _, err = ss.Team().Save(&o4) require.Nil(t, err) - if r1 := <-ss.Team().GetAllPrivateTeamListing(); r1.Err != nil { - t.Fatal(r1.Err) + if teams, err := ss.Team().GetAllPrivateTeamListing(); 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 false")