From dec3c8facbe653dfab75f66182d4da622bdec446 Mon Sep 17 00:00:00 2001 From: Puneeth Reddy <45575072+therealpuneeth20@users.noreply.github.com> Date: Mon, 29 Apr 2019 01:42:33 -0700 Subject: [PATCH] MM-15293: migrate commandstore.PermanentDeleteByUser to sync by default (#10744) --- app/user.go | 4 ++-- store/sqlstore/command_store.go | 14 +++++++------- store/store.go | 2 +- store/storetest/command_store.go | 4 ++-- store/storetest/mocks/CommandStore.go | 8 ++++---- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/app/user.go b/app/user.go index 9c1e7f6ee8..9f5a977937 100644 --- a/app/user.go +++ b/app/user.go @@ -1418,8 +1418,8 @@ func (a *App) PermanentDeleteUser(user *model.User) *model.AppError { return err } - if result := <-a.Srv.Store.Command().PermanentDeleteByUser(user.Id); result.Err != nil { - return result.Err + if err := a.Srv.Store.Command().PermanentDeleteByUser(user.Id); err != nil { + return err } if result := <-a.Srv.Store.Preference().PermanentDeleteByUser(user.Id); result.Err != nil { diff --git a/store/sqlstore/command_store.go b/store/sqlstore/command_store.go index a840c25c08..22485bc2f6 100644 --- a/store/sqlstore/command_store.go +++ b/store/sqlstore/command_store.go @@ -123,13 +123,13 @@ func (s SqlCommandStore) PermanentDeleteByTeam(teamId string) store.StoreChannel }) } -func (s SqlCommandStore) PermanentDeleteByUser(userId string) store.StoreChannel { - return store.Do(func(result *store.StoreResult) { - _, err := s.GetMaster().Exec("DELETE FROM Commands WHERE CreatorId = :UserId", map[string]interface{}{"UserId": userId}) - if err != nil { - result.Err = model.NewAppError("SqlCommandStore.DeleteByUser", "store.sql_command.save.delete_perm.app_error", nil, "id="+userId+", err="+err.Error(), http.StatusInternalServerError) - } - }) +func (s SqlCommandStore) PermanentDeleteByUser(userId string) *model.AppError { + _, err := s.GetMaster().Exec("DELETE FROM Commands WHERE CreatorId = :UserId", map[string]interface{}{"UserId": userId}) + if err != nil { + return model.NewAppError("SqlCommandStore.DeleteByUser", "store.sql_command.save.delete_perm.app_error", nil, "id="+userId+", err="+err.Error(), http.StatusInternalServerError) + } + + return nil } func (s SqlCommandStore) Update(cmd *model.Command) store.StoreChannel { diff --git a/store/store.go b/store/store.go index e6423cc445..f1b4c5675f 100644 --- a/store/store.go +++ b/store/store.go @@ -410,7 +410,7 @@ type CommandStore interface { GetByTrigger(teamId string, trigger string) StoreChannel Delete(commandId string, time int64) StoreChannel PermanentDeleteByTeam(teamId string) StoreChannel - PermanentDeleteByUser(userId string) StoreChannel + PermanentDeleteByUser(userId string) *model.AppError Update(hook *model.Command) StoreChannel AnalyticsCommandCount(teamId string) StoreChannel } diff --git a/store/storetest/command_store.go b/store/storetest/command_store.go index 4ada42a388..d74422fe87 100644 --- a/store/storetest/command_store.go +++ b/store/storetest/command_store.go @@ -196,8 +196,8 @@ func testCommandStoreDeleteByUser(t *testing.T, ss store.Store) { } } - if r2 := <-ss.Command().PermanentDeleteByUser(o1.CreatorId); r2.Err != nil { - t.Fatal(r2.Err) + if err := ss.Command().PermanentDeleteByUser(o1.CreatorId); err != nil { + t.Fatal(err) } if r3 := (<-ss.Command().Get(o1.Id)); r3.Err == nil { diff --git a/store/storetest/mocks/CommandStore.go b/store/storetest/mocks/CommandStore.go index 5e35e6072d..87bf55a317 100644 --- a/store/storetest/mocks/CommandStore.go +++ b/store/storetest/mocks/CommandStore.go @@ -119,15 +119,15 @@ func (_m *CommandStore) PermanentDeleteByTeam(teamId string) store.StoreChannel } // PermanentDeleteByUser provides a mock function with given fields: userId -func (_m *CommandStore) PermanentDeleteByUser(userId string) store.StoreChannel { +func (_m *CommandStore) PermanentDeleteByUser(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) } }