From eb3923c8350280202c20c35bf6ca6b2c33ee4a8e Mon Sep 17 00:00:00 2001 From: Puneeth Reddy <45575072+therealpuneeth20@users.noreply.github.com> Date: Mon, 29 Apr 2019 22:34:08 -0700 Subject: [PATCH] MM-15118: Migrates the "WebHook.DeleteIncoming" to Sync by default. (#10706) * cherry commit for DeleteIncoming and generate store mocks * go fmt the code and fix go vet issue --- app/channel.go | 2 +- app/webhook.go | 4 ++-- store/sqlstore/webhook_store.go | 15 +++++++-------- store/store.go | 2 +- store/storetest/mocks/WebhookStore.go | 8 ++++---- store/storetest/webhook_store.go | 4 ++-- 6 files changed, 17 insertions(+), 18 deletions(-) diff --git a/app/channel.go b/app/channel.go index 8f48b796a7..2e461b69f2 100644 --- a/app/channel.go +++ b/app/channel.go @@ -826,7 +826,7 @@ func (a *App) DeleteChannel(channel *model.Channel, userId string) *model.AppErr now := model.GetMillis() for _, hook := range incomingHooks { - if result := <-a.Srv.Store.Webhook().DeleteIncoming(hook.Id, now); result.Err != nil { + if err := a.Srv.Store.Webhook().DeleteIncoming(hook.Id, now); err != nil { mlog.Error(fmt.Sprintf("Encountered error deleting incoming webhook, id=%v", hook.Id)) } a.InvalidateCacheForWebhook(hook.Id) diff --git a/app/webhook.go b/app/webhook.go index 35a5a48699..dafeea1fae 100644 --- a/app/webhook.go +++ b/app/webhook.go @@ -360,8 +360,8 @@ func (a *App) DeleteIncomingWebhook(hookId string) *model.AppError { return model.NewAppError("DeleteIncomingWebhook", "api.incoming_webhook.disabled.app_error", nil, "", http.StatusNotImplemented) } - if result := <-a.Srv.Store.Webhook().DeleteIncoming(hookId, model.GetMillis()); result.Err != nil { - return result.Err + if err := a.Srv.Store.Webhook().DeleteIncoming(hookId, model.GetMillis()); err != nil { + return err } a.InvalidateCacheForWebhook(hookId) diff --git a/store/sqlstore/webhook_store.go b/store/sqlstore/webhook_store.go index 899ff3dfeb..938bc2480b 100644 --- a/store/sqlstore/webhook_store.go +++ b/store/sqlstore/webhook_store.go @@ -142,15 +142,14 @@ func (s SqlWebhookStore) GetIncoming(id string, allowFromCache bool) (*model.Inc return &webhook, nil } -func (s SqlWebhookStore) DeleteIncoming(webhookId string, time int64) store.StoreChannel { - return store.Do(func(result *store.StoreResult) { - _, err := s.GetMaster().Exec("Update IncomingWebhooks SET DeleteAt = :DeleteAt, UpdateAt = :UpdateAt WHERE Id = :Id", map[string]interface{}{"DeleteAt": time, "UpdateAt": time, "Id": webhookId}) - if err != nil { - result.Err = model.NewAppError("SqlWebhookStore.DeleteIncoming", "store.sql_webhooks.delete_incoming.app_error", nil, "id="+webhookId+", err="+err.Error(), http.StatusInternalServerError) - } +func (s SqlWebhookStore) DeleteIncoming(webhookId string, time int64) *model.AppError { + _, err := s.GetMaster().Exec("Update IncomingWebhooks SET DeleteAt = :DeleteAt, UpdateAt = :UpdateAt WHERE Id = :Id", map[string]interface{}{"DeleteAt": time, "UpdateAt": time, "Id": webhookId}) + if err != nil { + return model.NewAppError("SqlWebhookStore.DeleteIncoming", "store.sql_webhooks.delete_incoming.app_error", nil, "id="+webhookId+", err="+err.Error(), http.StatusInternalServerError) + } - s.InvalidateWebhookCache(webhookId) - }) + s.InvalidateWebhookCache(webhookId) + return nil } func (s SqlWebhookStore) PermanentDeleteIncomingByUser(userId string) *model.AppError { diff --git a/store/store.go b/store/store.go index 28b44e8b4c..19be5117f8 100644 --- a/store/store.go +++ b/store/store.go @@ -388,7 +388,7 @@ type WebhookStore interface { GetIncomingByTeam(teamId string, offset, limit int) ([]*model.IncomingWebhook, *model.AppError) UpdateIncoming(webhook *model.IncomingWebhook) (*model.IncomingWebhook, *model.AppError) GetIncomingByChannel(channelId string) ([]*model.IncomingWebhook, *model.AppError) - DeleteIncoming(webhookId string, time int64) StoreChannel + DeleteIncoming(webhookId string, time int64) *model.AppError PermanentDeleteIncomingByChannel(channelId string) *model.AppError PermanentDeleteIncomingByUser(userId string) *model.AppError diff --git a/store/storetest/mocks/WebhookStore.go b/store/storetest/mocks/WebhookStore.go index a51d30fa25..406562b86f 100644 --- a/store/storetest/mocks/WebhookStore.go +++ b/store/storetest/mocks/WebhookStore.go @@ -58,15 +58,15 @@ func (_m *WebhookStore) ClearCaches() { } // DeleteIncoming provides a mock function with given fields: webhookId, time -func (_m *WebhookStore) DeleteIncoming(webhookId string, time int64) store.StoreChannel { +func (_m *WebhookStore) DeleteIncoming(webhookId string, time int64) *model.AppError { ret := _m.Called(webhookId, time) - var r0 store.StoreChannel - if rf, ok := ret.Get(0).(func(string, int64) store.StoreChannel); ok { + var r0 *model.AppError + if rf, ok := ret.Get(0).(func(string, int64) *model.AppError); ok { r0 = rf(webhookId, time) } 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 ca9138d1e9..c62a6ac3e8 100644 --- a/store/storetest/webhook_store.go +++ b/store/storetest/webhook_store.go @@ -206,8 +206,8 @@ func testWebhookStoreDeleteIncoming(t *testing.T, ss store.Store) { t.Fatal("invalid returned webhook") } - if r2 := <-ss.Webhook().DeleteIncoming(o1.Id, model.GetMillis()); r2.Err != nil { - t.Fatal(r2.Err) + if err = ss.Webhook().DeleteIncoming(o1.Id, model.GetMillis()); err != nil { + t.Fatal(err) } webhook, err = ss.Webhook().GetIncoming(o1.Id, true)