diff --git a/app/export.go b/app/export.go index 9e3143ad82..232155160e 100644 --- a/app/export.go +++ b/app/export.go @@ -146,14 +146,12 @@ func (a *App) ExportAllTeams(writer io.Writer) *model.AppError { func (a *App) ExportAllChannels(writer io.Writer) *model.AppError { afterId := strings.Repeat("0", 26) for { - result := <-a.Srv.Store.Channel().GetAllChannelsForExportAfter(1000, afterId) + channels, err := a.Srv.Store.Channel().GetAllChannelsForExportAfter(1000, afterId) - if result.Err != nil { - return result.Err + if err != nil { + return err } - channels := result.Data.([]*model.ChannelForExport) - if len(channels) == 0 { break } diff --git a/store/sqlstore/channel_store.go b/store/sqlstore/channel_store.go index f8c5f4f73f..0e30e837d4 100644 --- a/store/sqlstore/channel_store.go +++ b/store/sqlstore/channel_store.go @@ -2465,32 +2465,29 @@ func (s SqlChannelStore) ClearAllCustomRoleAssignments() *model.AppError { return nil } -func (s SqlChannelStore) GetAllChannelsForExportAfter(limit int, afterId string) store.StoreChannel { - return store.Do(func(result *store.StoreResult) { - var data []*model.ChannelForExport - if _, err := s.GetReplica().Select(&data, ` - SELECT - Channels.*, - Teams.Name as TeamName, - Schemes.Name as SchemeName - FROM Channels - INNER JOIN - Teams ON Channels.TeamId = Teams.Id - LEFT JOIN - Schemes ON Channels.SchemeId = Schemes.Id - WHERE - Channels.Id > :AfterId - AND Channels.Type IN ('O', 'P') - ORDER BY - Id - LIMIT :Limit`, - map[string]interface{}{"AfterId": afterId, "Limit": limit}); err != nil { - result.Err = model.NewAppError("SqlChannelStore.GetAllChannelsForExportAfter", "store.sql_channel.get_all.app_error", nil, err.Error(), http.StatusInternalServerError) - return - } +func (s SqlChannelStore) GetAllChannelsForExportAfter(limit int, afterId string) ([]*model.ChannelForExport, *model.AppError) { + var channels []*model.ChannelForExport + if _, err := s.GetReplica().Select(&channels, ` + SELECT + Channels.*, + Teams.Name as TeamName, + Schemes.Name as SchemeName + FROM Channels + INNER JOIN + Teams ON Channels.TeamId = Teams.Id + LEFT JOIN + Schemes ON Channels.SchemeId = Schemes.Id + WHERE + Channels.Id > :AfterId + AND Channels.Type IN ('O', 'P') + ORDER BY + Id + LIMIT :Limit`, + map[string]interface{}{"AfterId": afterId, "Limit": limit}); err != nil { + return nil, model.NewAppError("SqlChannelStore.GetAllChannelsForExportAfter", "store.sql_channel.get_all.app_error", nil, err.Error(), http.StatusInternalServerError) + } - result.Data = data - }) + return channels, nil } func (s SqlChannelStore) GetChannelMembersForExport(userId string, teamId string) ([]*model.ChannelMemberForExport, *model.AppError) { diff --git a/store/store.go b/store/store.go index 2f038d3755..e5d8588cf1 100644 --- a/store/store.go +++ b/store/store.go @@ -194,7 +194,7 @@ type ChannelStore interface { ResetAllChannelSchemes() StoreChannel ClearAllCustomRoleAssignments() *model.AppError MigratePublicChannels() error - GetAllChannelsForExportAfter(limit int, afterId string) StoreChannel + GetAllChannelsForExportAfter(limit int, afterId string) ([]*model.ChannelForExport, *model.AppError) GetAllDirectChannelsForExportAfter(limit int, afterId string) StoreChannel GetChannelMembersForExport(userId string, teamId string) ([]*model.ChannelMemberForExport, *model.AppError) RemoveAllDeactivatedMembers(channelId string) *model.AppError diff --git a/store/storetest/channel_store.go b/store/storetest/channel_store.go index fb0e41c2ff..82afadf5d7 100644 --- a/store/storetest/channel_store.go +++ b/store/storetest/channel_store.go @@ -3290,9 +3290,8 @@ func testChannelStoreGetAllChannelsForExportAfter(t *testing.T, ss store.Store) _, err = ss.Channel().Save(&c1, -1) require.Nil(t, err) - r1 := <-ss.Channel().GetAllChannelsForExportAfter(10000, strings.Repeat("0", 26)) - assert.Nil(t, r1.Err) - d1 := r1.Data.([]*model.ChannelForExport) + d1, err := ss.Channel().GetAllChannelsForExportAfter(10000, strings.Repeat("0", 26)) + assert.Nil(t, err) found := false for _, c := range d1 { diff --git a/store/storetest/mocks/ChannelStore.go b/store/storetest/mocks/ChannelStore.go index 8564149df1..1e2950763a 100644 --- a/store/storetest/mocks/ChannelStore.go +++ b/store/storetest/mocks/ChannelStore.go @@ -263,19 +263,28 @@ func (_m *ChannelStore) GetAllChannels(page int, perPage int, opts store.Channel } // GetAllChannelsForExportAfter provides a mock function with given fields: limit, afterId -func (_m *ChannelStore) GetAllChannelsForExportAfter(limit int, afterId string) store.StoreChannel { +func (_m *ChannelStore) GetAllChannelsForExportAfter(limit int, afterId string) ([]*model.ChannelForExport, *model.AppError) { ret := _m.Called(limit, afterId) - var r0 store.StoreChannel - if rf, ok := ret.Get(0).(func(int, string) store.StoreChannel); ok { + var r0 []*model.ChannelForExport + if rf, ok := ret.Get(0).(func(int, string) []*model.ChannelForExport); ok { r0 = rf(limit, afterId) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(store.StoreChannel) + r0 = ret.Get(0).([]*model.ChannelForExport) } } - return r0 + var r1 *model.AppError + if rf, ok := ret.Get(1).(func(int, string) *model.AppError); ok { + r1 = rf(limit, afterId) + } else { + if ret.Get(1) != nil { + r1 = ret.Get(1).(*model.AppError) + } + } + + return r0, r1 } // GetAllDirectChannelsForExportAfter provides a mock function with given fields: limit, afterId