From 0d1c69927f48d6e16d3ab939c2f37d3c13bcf2bf Mon Sep 17 00:00:00 2001 From: tengis b Date: Tue, 23 Apr 2019 21:40:41 +0900 Subject: [PATCH] Migrate PermanentDeleteOutgoingByChannel to Sync (#10673) --- app/channel.go | 4 ++-- store/sqlstore/webhook_store.go | 16 ++++++++-------- store/store.go | 2 +- store/storetest/mocks/WebhookStore.go | 8 ++++---- store/storetest/webhook_store.go | 4 ++-- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/app/channel.go b/app/channel.go index 6bf9083942..d53396ef54 100644 --- a/app/channel.go +++ b/app/channel.go @@ -1856,8 +1856,8 @@ func (a *App) PermanentDeleteChannel(channel *model.Channel) *model.AppError { return result.Err } - if result := <-a.Srv.Store.Webhook().PermanentDeleteOutgoingByChannel(channel.Id); result.Err != nil { - return result.Err + if err := a.Srv.Store.Webhook().PermanentDeleteOutgoingByChannel(channel.Id); err != nil { + return err } if result := <-a.Srv.Store.Channel().PermanentDelete(channel.Id); result.Err != nil { diff --git a/store/sqlstore/webhook_store.go b/store/sqlstore/webhook_store.go index cf826df881..b7081ab7e3 100644 --- a/store/sqlstore/webhook_store.go +++ b/store/sqlstore/webhook_store.go @@ -305,15 +305,15 @@ func (s SqlWebhookStore) PermanentDeleteOutgoingByUser(userId string) store.Stor }) } -func (s SqlWebhookStore) PermanentDeleteOutgoingByChannel(channelId string) store.StoreChannel { - return store.Do(func(result *store.StoreResult) { - _, err := s.GetMaster().Exec("DELETE FROM OutgoingWebhooks WHERE ChannelId = :ChannelId", map[string]interface{}{"ChannelId": channelId}) - if err != nil { - result.Err = model.NewAppError("SqlWebhookStore.DeleteOutgoingByChannel", "store.sql_webhooks.permanent_delete_outgoing_by_channel.app_error", nil, "id="+channelId+", err="+err.Error(), http.StatusInternalServerError) - } +func (s SqlWebhookStore) PermanentDeleteOutgoingByChannel(channelId string) *model.AppError { + _, err := s.GetMaster().Exec("DELETE FROM OutgoingWebhooks WHERE ChannelId = :ChannelId", map[string]interface{}{"ChannelId": channelId}) + if err != nil { + return model.NewAppError("SqlWebhookStore.DeleteOutgoingByChannel", "store.sql_webhooks.permanent_delete_outgoing_by_channel.app_error", nil, "id="+channelId+", err="+err.Error(), http.StatusInternalServerError) + } - s.ClearCaches() - }) + s.ClearCaches() + + return nil } func (s SqlWebhookStore) UpdateOutgoing(hook *model.OutgoingWebhook) store.StoreChannel { diff --git a/store/store.go b/store/store.go index 8d03cccb90..db54f13aef 100644 --- a/store/store.go +++ b/store/store.go @@ -393,7 +393,7 @@ type WebhookStore interface { GetOutgoingByChannel(channelId string, offset, limit int) StoreChannel GetOutgoingByTeam(teamId string, offset, limit int) StoreChannel DeleteOutgoing(webhookId string, time int64) StoreChannel - PermanentDeleteOutgoingByChannel(channelId string) StoreChannel + PermanentDeleteOutgoingByChannel(channelId string) *model.AppError PermanentDeleteOutgoingByUser(userId string) StoreChannel UpdateOutgoing(hook *model.OutgoingWebhook) StoreChannel diff --git a/store/storetest/mocks/WebhookStore.go b/store/storetest/mocks/WebhookStore.go index 5753d8db4e..c9ebfb492a 100644 --- a/store/storetest/mocks/WebhookStore.go +++ b/store/storetest/mocks/WebhookStore.go @@ -275,15 +275,15 @@ func (_m *WebhookStore) PermanentDeleteIncomingByUser(userId string) store.Store } // PermanentDeleteOutgoingByChannel provides a mock function with given fields: channelId -func (_m *WebhookStore) PermanentDeleteOutgoingByChannel(channelId string) store.StoreChannel { +func (_m *WebhookStore) PermanentDeleteOutgoingByChannel(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) } } diff --git a/store/storetest/webhook_store.go b/store/storetest/webhook_store.go index fec1bda826..1d6043bb01 100644 --- a/store/storetest/webhook_store.go +++ b/store/storetest/webhook_store.go @@ -428,8 +428,8 @@ func testWebhookStoreDeleteOutgoingByChannel(t *testing.T, ss store.Store) { } } - if r2 := <-ss.Webhook().PermanentDeleteOutgoingByChannel(o1.ChannelId); r2.Err != nil { - t.Fatal(r2.Err) + if err := ss.Webhook().PermanentDeleteOutgoingByChannel(o1.ChannelId); err != nil { + t.Fatal(err) } if r3 := (<-ss.Webhook().GetOutgoing(o1.Id)); r3.Err == nil {