From 2ce36c2eb1c5932481aff80e0f5c033fee779c79 Mon Sep 17 00:00:00 2001 From: piperRyan <35411044+piperRyan@users.noreply.github.com> Date: Wed, 19 Jun 2019 03:40:05 -0600 Subject: [PATCH] Migrates "Channel.GetAll" to Sync by default (#11281) --- cmd/mattermost/commands/channel.go | 4 +--- store/sqlstore/channel_store.go | 17 +++++++---------- store/store.go | 2 +- store/storetest/channel_store.go | 5 ++--- store/storetest/mocks/ChannelStore.go | 19 ++++++++++++++----- 5 files changed, 25 insertions(+), 22 deletions(-) diff --git a/cmd/mattermost/commands/channel.go b/cmd/mattermost/commands/channel.go index 530c8454ed..a5f7a30681 100644 --- a/cmd/mattermost/commands/channel.go +++ b/cmd/mattermost/commands/channel.go @@ -444,11 +444,9 @@ func listChannelsCmdF(command *cobra.Command, args []string) error { CommandPrintErrorln("Unable to find team '" + args[i] + "'") continue } - if result := <-a.Srv.Store.Channel().GetAll(team.Id); result.Err != nil { + if channels, chanErr := a.Srv.Store.Channel().GetAll(team.Id); chanErr != nil { CommandPrintErrorln("Unable to list channels for '" + args[i] + "'") } else { - channels := result.Data.([]*model.Channel) - for _, channel := range channels { if channel.DeleteAt > 0 { CommandPrettyPrintln(channel.Name + " (archived)") diff --git a/store/sqlstore/channel_store.go b/store/sqlstore/channel_store.go index cf11e5f604..f8c5f4f73f 100644 --- a/store/sqlstore/channel_store.go +++ b/store/sqlstore/channel_store.go @@ -1829,18 +1829,15 @@ func (s SqlChannelStore) IncrementMentionCount(channelId string, userId string) }) } -func (s SqlChannelStore) GetAll(teamId string) store.StoreChannel { - return store.Do(func(result *store.StoreResult) { - var data []*model.Channel - _, err := s.GetReplica().Select(&data, "SELECT * FROM Channels WHERE TeamId = :TeamId AND Type != 'D' ORDER BY Name", map[string]interface{}{"TeamId": teamId}) +func (s SqlChannelStore) GetAll(teamId string) ([]*model.Channel, *model.AppError) { + var data []*model.Channel + _, err := s.GetReplica().Select(&data, "SELECT * FROM Channels WHERE TeamId = :TeamId AND Type != 'D' ORDER BY Name", map[string]interface{}{"TeamId": teamId}) - if err != nil { - result.Err = model.NewAppError("SqlChannelStore.GetAll", "store.sql_channel.get_all.app_error", nil, "teamId="+teamId+", err="+err.Error(), http.StatusInternalServerError) - return - } + if err != nil { + return nil, model.NewAppError("SqlChannelStore.GetAll", "store.sql_channel.get_all.app_error", nil, "teamId="+teamId+", err="+err.Error(), http.StatusInternalServerError) + } - result.Data = data - }) + return data, nil } func (s SqlChannelStore) GetChannelsByIds(channelIds []string) ([]*model.Channel, *model.AppError) { diff --git a/store/store.go b/store/store.go index 551e5184a4..2f038d3755 100644 --- a/store/store.go +++ b/store/store.go @@ -154,7 +154,7 @@ type ChannelStore interface { GetPublicChannelsByIdsForTeam(teamId string, channelIds []string) (*model.ChannelList, *model.AppError) GetChannelCounts(teamId string, userId string) (*model.ChannelCounts, *model.AppError) GetTeamChannels(teamId string) (*model.ChannelList, *model.AppError) - GetAll(teamId string) StoreChannel + GetAll(teamId string) ([]*model.Channel, *model.AppError) GetChannelsByIds(channelIds []string) ([]*model.Channel, *model.AppError) GetForPost(postId string) (*model.Channel, *model.AppError) SaveMember(member *model.ChannelMember) StoreChannel diff --git a/store/storetest/channel_store.go b/store/storetest/channel_store.go index a924b57396..fb0e41c2ff 100644 --- a/store/storetest/channel_store.go +++ b/store/storetest/channel_store.go @@ -423,10 +423,9 @@ func testChannelStoreGet(t *testing.T, ss store.Store, s SqlSupplier) { } } - if r3 := <-ss.Channel().GetAll(o1.TeamId); r3.Err != nil { - t.Fatal(r3.Err) + if channels, chanErr := ss.Channel().GetAll(o1.TeamId); chanErr != nil { + t.Fatal(chanErr) } else { - channels := r3.Data.([]*model.Channel) if len(channels) == 0 { t.Fatal("too little") } diff --git a/store/storetest/mocks/ChannelStore.go b/store/storetest/mocks/ChannelStore.go index e2e99c1230..8564149df1 100644 --- a/store/storetest/mocks/ChannelStore.go +++ b/store/storetest/mocks/ChannelStore.go @@ -181,19 +181,28 @@ func (_m *ChannelStore) Get(id string, allowFromCache bool) (*model.Channel, *mo } // GetAll provides a mock function with given fields: teamId -func (_m *ChannelStore) GetAll(teamId string) store.StoreChannel { +func (_m *ChannelStore) GetAll(teamId string) ([]*model.Channel, *model.AppError) { ret := _m.Called(teamId) - var r0 store.StoreChannel - if rf, ok := ret.Get(0).(func(string) store.StoreChannel); ok { + var r0 []*model.Channel + if rf, ok := ret.Get(0).(func(string) []*model.Channel); ok { r0 = rf(teamId) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(store.StoreChannel) + r0 = ret.Get(0).([]*model.Channel) } } - return r0 + var r1 *model.AppError + if rf, ok := ret.Get(1).(func(string) *model.AppError); ok { + r1 = rf(teamId) + } else { + if ret.Get(1) != nil { + r1 = ret.Get(1).(*model.AppError) + } + } + + return r0, r1 } // GetAllChannelMembersForUser provides a mock function with given fields: userId, allowFromCache, includeDeleted