Migrate "Channel.PermanentDeleteMembersByUser" to Sync by default (#11243)

* Change PermanentDeleteMembersByUser to sync by default

* Address comments
This commit is contained in:
Shobhit Gupta
2019-06-26 03:09:29 -07:00
committed by Jesús Espino
parent 4cf6ae6808
commit 879883e9a3
5 changed files with 14 additions and 14 deletions

View File

@@ -1462,8 +1462,8 @@ func (a *App) PermanentDeleteUser(user *model.User) *model.AppError {
return err
}
if result := <-a.Srv.Store.Channel().PermanentDeleteMembersByUser(user.Id); result.Err != nil {
return result.Err
if err := a.Srv.Store.Channel().PermanentDeleteMembersByUser(user.Id); err != nil {
return err
}
if err := a.Srv.Store.Post().PermanentDeleteByUser(user.Id); err != nil {

View File

@@ -1717,12 +1717,11 @@ func (s SqlChannelStore) RemoveAllDeactivatedMembers(channelId string) *model.Ap
return nil
}
func (s SqlChannelStore) PermanentDeleteMembersByUser(userId string) store.StoreChannel {
return store.Do(func(result *store.StoreResult) {
if _, err := s.GetMaster().Exec("DELETE FROM ChannelMembers WHERE UserId = :UserId", map[string]interface{}{"UserId": userId}); err != nil {
result.Err = model.NewAppError("SqlChannelStore.RemoveMember", "store.sql_channel.permanent_delete_members_by_user.app_error", nil, "user_id="+userId+", "+err.Error(), http.StatusInternalServerError)
}
})
func (s SqlChannelStore) PermanentDeleteMembersByUser(userId string) *model.AppError {
if _, err := s.GetMaster().Exec("DELETE FROM ChannelMembers WHERE UserId = :UserId", map[string]interface{}{"UserId": userId}); err != nil {
return model.NewAppError("SqlChannelStore.RemoveMember", "store.sql_channel.permanent_delete_members_by_user.app_error", nil, "user_id="+userId+", "+err.Error(), http.StatusInternalServerError)
}
return nil
}
func (s SqlChannelStore) UpdateLastViewedAt(channelIds []string, userId string) (map[string]int64, *model.AppError) {

View File

@@ -174,7 +174,7 @@ type ChannelStore interface {
GetMemberCount(channelId string, allowFromCache bool) (int64, *model.AppError)
GetPinnedPosts(channelId string) StoreChannel
RemoveMember(channelId string, userId string) *model.AppError
PermanentDeleteMembersByUser(userId string) StoreChannel
PermanentDeleteMembersByUser(userId string) *model.AppError
PermanentDeleteMembersByChannel(channelId string) *model.AppError
UpdateLastViewedAt(channelIds []string, userId string) (map[string]int64, *model.AppError)
IncrementMentionCount(channelId string, userId string) *model.AppError

View File

@@ -984,7 +984,8 @@ func testChannelDeleteMemberStore(t *testing.T, ss store.Store) {
t.Fatal("should have saved 2 members")
}
store.Must(ss.Channel().PermanentDeleteMembersByUser(o2.UserId))
err = ss.Channel().PermanentDeleteMembersByUser(o2.UserId)
require.Nil(t, err)
count, err = ss.Channel().GetMemberCount(o1.ChannelId, false)
require.Nil(t, err)

View File

@@ -1163,15 +1163,15 @@ func (_m *ChannelStore) PermanentDeleteMembersByChannel(channelId string) *model
}
// PermanentDeleteMembersByUser provides a mock function with given fields: userId
func (_m *ChannelStore) PermanentDeleteMembersByUser(userId string) store.StoreChannel {
func (_m *ChannelStore) PermanentDeleteMembersByUser(userId string) *model.AppError {
ret := _m.Called(userId)
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(userId)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(store.StoreChannel)
r0 = ret.Get(0).(*model.AppError)
}
}