Migrates Channel.GetAllChannelsForExportAfter to sync by default (#11273)

This commit is contained in:
Rodrigo Villablanca Vásquez
2019-06-19 07:31:51 -04:00
committed by George Goldberg
parent 2ce36c2eb1
commit c40017b39d
5 changed files with 42 additions and 39 deletions

View File

@@ -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
}

View File

@@ -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) {

View File

@@ -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

View File

@@ -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 {

View File

@@ -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