Migrate Channel.RemoveAllDeactivatedMembers to Sync by default (#11270)

* Migrate Channel.RemoveAllDeactivatedMembers to Sync by default

* Indent query string
This commit is contained in:
Shobhit Gupta
2019-06-18 14:09:15 -07:00
committed by Jesús Espino
parent 6555bea117
commit e92ecf6696
5 changed files with 30 additions and 31 deletions

View File

@@ -1956,8 +1956,8 @@ func (a *App) PermanentDeleteChannel(channel *model.Channel) *model.AppError {
// is in progress, and therefore should not be used from the API without first fixing this potential race condition.
func (a *App) MoveChannel(team *model.Team, channel *model.Channel, user *model.User, removeDeactivatedMembers bool) *model.AppError {
if removeDeactivatedMembers {
if result := <-a.Srv.Store.Channel().RemoveAllDeactivatedMembers(channel.Id); result.Err != nil {
return result.Err
if err := a.Srv.Store.Channel().RemoveAllDeactivatedMembers(channel.Id); err != nil {
return err
}
}

View File

@@ -1693,30 +1693,29 @@ func (s SqlChannelStore) RemoveMember(channelId string, userId string) *model.Ap
return nil
}
func (s SqlChannelStore) RemoveAllDeactivatedMembers(channelId string) store.StoreChannel {
return store.Do(func(result *store.StoreResult) {
query := `
DELETE
FROM
ChannelMembers
WHERE
UserId IN (
SELECT
Id
FROM
Users
WHERE
Users.DeleteAt != 0
)
AND
ChannelMembers.ChannelId = :ChannelId
`
func (s SqlChannelStore) RemoveAllDeactivatedMembers(channelId string) *model.AppError {
query := `
DELETE
FROM
ChannelMembers
WHERE
UserId IN (
SELECT
Id
FROM
Users
WHERE
Users.DeleteAt != 0
)
AND
ChannelMembers.ChannelId = :ChannelId
`
_, err := s.GetMaster().Exec(query, map[string]interface{}{"ChannelId": channelId})
if err != nil {
result.Err = model.NewAppError("SqlChannelStore.RemoveAllDeactivatedMembers", "store.sql_channel.remove_all_deactivated_members.app_error", nil, "channel_id="+channelId+", "+err.Error(), http.StatusInternalServerError)
}
})
_, err := s.GetMaster().Exec(query, map[string]interface{}{"ChannelId": channelId})
if err != nil {
return model.NewAppError("SqlChannelStore.RemoveAllDeactivatedMembers", "store.sql_channel.remove_all_deactivated_members.app_error", nil, "channel_id="+channelId+", "+err.Error(), http.StatusInternalServerError)
}
return nil
}
func (s SqlChannelStore) PermanentDeleteMembersByUser(userId string) store.StoreChannel {

View File

@@ -197,7 +197,7 @@ type ChannelStore interface {
GetAllChannelsForExportAfter(limit int, afterId string) StoreChannel
GetAllDirectChannelsForExportAfter(limit int, afterId string) StoreChannel
GetChannelMembersForExport(userId string, teamId string) ([]*model.ChannelMemberForExport, *model.AppError)
RemoveAllDeactivatedMembers(channelId string) StoreChannel
RemoveAllDeactivatedMembers(channelId string) *model.AppError
GetChannelsBatchForIndexing(startTime, endTime int64, limit int) ([]*model.Channel, *model.AppError)
UserBelongsToChannels(userId string, channelIds []string) (bool, *model.AppError)
}

View File

@@ -3426,7 +3426,7 @@ func testChannelStoreRemoveAllDeactivatedMembers(t *testing.T, ss store.Store) {
require.Nil(t, err)
// Remove all deactivated users from the channel.
assert.Nil(t, (<-ss.Channel().RemoveAllDeactivatedMembers(c1.Id)).Err)
assert.Nil(t, ss.Channel().RemoveAllDeactivatedMembers(c1.Id))
// Get all the channel members. Check there is now only 1: m3.
r2 := <-ss.Channel().GetMembers(c1.Id, 0, 1000)

View File

@@ -980,15 +980,15 @@ func (_m *ChannelStore) PermanentDeleteMembersByUser(userId string) store.StoreC
}
// RemoveAllDeactivatedMembers provides a mock function with given fields: channelId
func (_m *ChannelStore) RemoveAllDeactivatedMembers(channelId string) store.StoreChannel {
func (_m *ChannelStore) RemoveAllDeactivatedMembers(channelId string) *model.AppError {
ret := _m.Called(channelId)
var r0 store.StoreChannel
if rf, ok := ret.Get(0).(func(string) store.StoreChannel); ok {
var r0 *model.AppError
if rf, ok := ret.Get(0).(func(string) *model.AppError); ok {
r0 = rf(channelId)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(store.StoreChannel)
r0 = ret.Get(0).(*model.AppError)
}
}