From eea8df75b0a9e270dec6c6e43e5b0421e4721933 Mon Sep 17 00:00:00 2001 From: Shobhit Gupta Date: Tue, 2 Jul 2019 13:06:03 -0700 Subject: [PATCH] Migrate Channel.GetChannelsByScheme to Sync by default (#11278) --- app/scheme.go | 6 +----- store/sqlstore/channel_store.go | 17 +++++++---------- store/store.go | 2 +- store/storetest/channel_store.go | 15 ++++++--------- store/storetest/mocks/ChannelStore.go | 19 ++++++++++++++----- 5 files changed, 29 insertions(+), 30 deletions(-) diff --git a/app/scheme.go b/app/scheme.go index 743081db61..36567ae07d 100644 --- a/app/scheme.go +++ b/app/scheme.go @@ -146,11 +146,7 @@ func (a *App) GetChannelsForScheme(scheme *model.Scheme, offset int, limit int) if err := a.IsPhase2MigrationCompleted(); err != nil { return nil, err } - result := <-a.Srv.Store.Channel().GetChannelsByScheme(scheme.Id, offset, limit) - if result.Err != nil { - return nil, result.Err - } - return result.Data.(model.ChannelList), nil + return a.Srv.Store.Channel().GetChannelsByScheme(scheme.Id, offset, limit) } func (a *App) IsPhase2MigrationCompleted() *model.AppError { diff --git a/store/sqlstore/channel_store.go b/store/sqlstore/channel_store.go index 48d638ca9c..02fb641053 100644 --- a/store/sqlstore/channel_store.go +++ b/store/sqlstore/channel_store.go @@ -2352,16 +2352,13 @@ func (s SqlChannelStore) GetMembersByIds(channelId string, userIds []string) (*m return dbMembers.ToModel(), nil } -func (s SqlChannelStore) GetChannelsByScheme(schemeId string, offset int, limit int) store.StoreChannel { - return store.Do(func(result *store.StoreResult) { - var channels model.ChannelList - _, err := s.GetReplica().Select(&channels, "SELECT * FROM Channels WHERE SchemeId = :SchemeId ORDER BY DisplayName LIMIT :Limit OFFSET :Offset", map[string]interface{}{"SchemeId": schemeId, "Offset": offset, "Limit": limit}) - if err != nil { - result.Err = model.NewAppError("SqlChannelStore.GetChannelsByScheme", "store.sql_channel.get_by_scheme.app_error", nil, "schemeId="+schemeId+" "+err.Error(), http.StatusInternalServerError) - return - } - result.Data = channels - }) +func (s SqlChannelStore) GetChannelsByScheme(schemeId string, offset int, limit int) (model.ChannelList, *model.AppError) { + var channels model.ChannelList + _, err := s.GetReplica().Select(&channels, "SELECT * FROM Channels WHERE SchemeId = :SchemeId ORDER BY DisplayName LIMIT :Limit OFFSET :Offset", map[string]interface{}{"SchemeId": schemeId, "Offset": offset, "Limit": limit}) + if err != nil { + return nil, model.NewAppError("SqlChannelStore.GetChannelsByScheme", "store.sql_channel.get_by_scheme.app_error", nil, "schemeId="+schemeId+" "+err.Error(), http.StatusInternalServerError) + } + return channels, nil } // This function does the Advanced Permissions Phase 2 migration for ChannelMember objects. It performs the migration diff --git a/store/store.go b/store/store.go index eedfbfc9e9..45b56835fd 100644 --- a/store/store.go +++ b/store/store.go @@ -191,7 +191,7 @@ type ChannelStore interface { AnalyticsDeletedTypeCount(teamId string, channelType string) (int64, *model.AppError) GetChannelUnread(channelId, userId string) (*model.ChannelUnread, *model.AppError) ClearCaches() - GetChannelsByScheme(schemeId string, offset int, limit int) StoreChannel + GetChannelsByScheme(schemeId string, offset int, limit int) (model.ChannelList, *model.AppError) MigrateChannelMembers(fromChannelId string, fromUserId string) (map[string]string, *model.AppError) ResetAllChannelSchemes() *model.AppError ClearAllCustomRoleAssignments() *model.AppError diff --git a/store/storetest/channel_store.go b/store/storetest/channel_store.go index e9a79f7021..8162fb6d77 100644 --- a/store/storetest/channel_store.go +++ b/store/storetest/channel_store.go @@ -3073,21 +3073,18 @@ func testChannelStoreGetChannelsByScheme(t *testing.T, ss store.Store) { _, _ = ss.Channel().Save(c3, 100) // Get the channels by a valid Scheme ID. - res1 := <-ss.Channel().GetChannelsByScheme(s1.Id, 0, 100) - assert.Nil(t, res1.Err) - d1 := res1.Data.(model.ChannelList) + d1, err := ss.Channel().GetChannelsByScheme(s1.Id, 0, 100) + assert.Nil(t, err) assert.Len(t, d1, 2) // Get the channels by a valid Scheme ID where there aren't any matching Channel. - res2 := <-ss.Channel().GetChannelsByScheme(s2.Id, 0, 100) - assert.Nil(t, res2.Err) - d2 := res2.Data.(model.ChannelList) + d2, err := ss.Channel().GetChannelsByScheme(s2.Id, 0, 100) + assert.Nil(t, err) assert.Len(t, d2, 0) // Get the channels by an invalid Scheme ID. - res3 := <-ss.Channel().GetChannelsByScheme(model.NewId(), 0, 100) - assert.Nil(t, res3.Err) - d3 := res3.Data.(model.ChannelList) + d3, err := ss.Channel().GetChannelsByScheme(model.NewId(), 0, 100) + assert.Nil(t, err) assert.Len(t, d3, 0) } diff --git a/store/storetest/mocks/ChannelStore.go b/store/storetest/mocks/ChannelStore.go index 763c04eb2e..e35132263f 100644 --- a/store/storetest/mocks/ChannelStore.go +++ b/store/storetest/mocks/ChannelStore.go @@ -620,19 +620,28 @@ func (_m *ChannelStore) GetChannelsByIds(channelIds []string) ([]*model.Channel, } // GetChannelsByScheme provides a mock function with given fields: schemeId, offset, limit -func (_m *ChannelStore) GetChannelsByScheme(schemeId string, offset int, limit int) store.StoreChannel { +func (_m *ChannelStore) GetChannelsByScheme(schemeId string, offset int, limit int) (model.ChannelList, *model.AppError) { ret := _m.Called(schemeId, offset, limit) - var r0 store.StoreChannel - if rf, ok := ret.Get(0).(func(string, int, int) store.StoreChannel); ok { + var r0 model.ChannelList + if rf, ok := ret.Get(0).(func(string, int, int) model.ChannelList); ok { r0 = rf(schemeId, offset, limit) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(store.StoreChannel) + r0 = ret.Get(0).(model.ChannelList) } } - return r0 + var r1 *model.AppError + if rf, ok := ret.Get(1).(func(string, int, int) *model.AppError); ok { + r1 = rf(schemeId, offset, limit) + } else { + if ret.Get(1) != nil { + r1 = ret.Get(1).(*model.AppError) + } + } + + return r0, r1 } // GetDeleted provides a mock function with given fields: team_id, offset, limit