mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
GH-10652: Migrate WebHookStore.GetOutgoingList method to sync by default (#10703)
* Migrate WebHookStore.GetOutgoingList method to sync by default * go fmt the code
This commit is contained in:
committed by
Jesús Espino
parent
f7982216e4
commit
9fc05b5865
@@ -504,11 +504,7 @@ func (a *App) GetOutgoingWebhooksPage(page, perPage int) ([]*model.OutgoingWebho
|
||||
return nil, model.NewAppError("GetOutgoingWebhooksPage", "api.outgoing_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
if result := <-a.Srv.Store.Webhook().GetOutgoingList(page*perPage, perPage); result.Err != nil {
|
||||
return nil, result.Err
|
||||
} else {
|
||||
return result.Data.([]*model.OutgoingWebhook), nil
|
||||
}
|
||||
return a.Srv.Store.Webhook().GetOutgoingList(page*perPage, perPage)
|
||||
}
|
||||
|
||||
func (a *App) GetOutgoingWebhooksForChannelPage(channelId string, page, perPage int) ([]*model.OutgoingWebhook, *model.AppError) {
|
||||
|
||||
@@ -234,16 +234,14 @@ func (s SqlWebhookStore) GetOutgoing(id string) (*model.OutgoingWebhook, *model.
|
||||
return &webhook, nil
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) GetOutgoingList(offset, limit int) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
var webhooks []*model.OutgoingWebhook
|
||||
func (s SqlWebhookStore) GetOutgoingList(offset, limit int) ([]*model.OutgoingWebhook, *model.AppError) {
|
||||
var webhooks []*model.OutgoingWebhook
|
||||
|
||||
if _, err := s.GetReplica().Select(&webhooks, "SELECT * FROM OutgoingWebhooks WHERE DeleteAt = 0 LIMIT :Limit OFFSET :Offset", map[string]interface{}{"Offset": offset, "Limit": limit}); err != nil {
|
||||
result.Err = model.NewAppError("SqlWebhookStore.GetOutgoingList", "store.sql_webhooks.get_outgoing_by_channel.app_error", nil, "err="+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
if _, err := s.GetReplica().Select(&webhooks, "SELECT * FROM OutgoingWebhooks WHERE DeleteAt = 0 LIMIT :Limit OFFSET :Offset", map[string]interface{}{"Offset": offset, "Limit": limit}); err != nil {
|
||||
return nil, model.NewAppError("SqlWebhookStore.GetOutgoingList", "store.sql_webhooks.get_outgoing_by_channel.app_error", nil, "err="+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
result.Data = webhooks
|
||||
})
|
||||
return webhooks, nil
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) GetOutgoingByChannel(channelId string, offset, limit int) store.StoreChannel {
|
||||
|
||||
@@ -389,7 +389,7 @@ type WebhookStore interface {
|
||||
|
||||
SaveOutgoing(webhook *model.OutgoingWebhook) (*model.OutgoingWebhook, *model.AppError)
|
||||
GetOutgoing(id string) (*model.OutgoingWebhook, *model.AppError)
|
||||
GetOutgoingList(offset, limit int) StoreChannel
|
||||
GetOutgoingList(offset, limit int) ([]*model.OutgoingWebhook, *model.AppError)
|
||||
GetOutgoingByChannel(channelId string, offset, limit int) StoreChannel
|
||||
GetOutgoingByTeam(teamId string, offset, limit int) StoreChannel
|
||||
DeleteOutgoing(webhookId string, time int64) StoreChannel
|
||||
|
||||
@@ -247,19 +247,28 @@ func (_m *WebhookStore) GetOutgoingByTeam(teamId string, offset int, limit int)
|
||||
}
|
||||
|
||||
// GetOutgoingList provides a mock function with given fields: offset, limit
|
||||
func (_m *WebhookStore) GetOutgoingList(offset int, limit int) store.StoreChannel {
|
||||
func (_m *WebhookStore) GetOutgoingList(offset int, limit int) ([]*model.OutgoingWebhook, *model.AppError) {
|
||||
ret := _m.Called(offset, limit)
|
||||
|
||||
var r0 store.StoreChannel
|
||||
if rf, ok := ret.Get(0).(func(int, int) store.StoreChannel); ok {
|
||||
var r0 []*model.OutgoingWebhook
|
||||
if rf, ok := ret.Get(0).(func(int, int) []*model.OutgoingWebhook); ok {
|
||||
r0 = rf(offset, limit)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(store.StoreChannel)
|
||||
r0 = ret.Get(0).([]*model.OutgoingWebhook)
|
||||
}
|
||||
}
|
||||
|
||||
return r0
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(int, int) *model.AppError); ok {
|
||||
r1 = rf(offset, limit)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
}
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// InvalidateWebhookCache provides a mock function with given fields: webhook
|
||||
|
||||
@@ -328,10 +328,10 @@ func testWebhookStoreGetOutgoingList(t *testing.T, ss store.Store) {
|
||||
|
||||
o2, _ = ss.Webhook().SaveOutgoing(o2)
|
||||
|
||||
if r1 := <-ss.Webhook().GetOutgoingList(0, 1000); r1.Err != nil {
|
||||
t.Fatal(r1.Err)
|
||||
if r1, err := ss.Webhook().GetOutgoingList(0, 1000); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
hooks := r1.Data.([]*model.OutgoingWebhook)
|
||||
hooks := r1
|
||||
found1 := false
|
||||
found2 := false
|
||||
|
||||
@@ -353,10 +353,10 @@ func testWebhookStoreGetOutgoingList(t *testing.T, ss store.Store) {
|
||||
}
|
||||
}
|
||||
|
||||
if result := <-ss.Webhook().GetOutgoingList(0, 2); result.Err != nil {
|
||||
t.Fatal(result.Err)
|
||||
if result, err := ss.Webhook().GetOutgoingList(0, 2); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
if len(result.Data.([]*model.OutgoingWebhook)) != 2 {
|
||||
if len(result) != 2 {
|
||||
t.Fatal("wrong number of hooks returned")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user