mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
[MM-15121] Migrate "WebHook.GetIncomingList" to Sync by default (#10666)
* SyncStore: migrate WebHooks.SaveIncoming method to Sync
* MM-15121 Migrate WebHook.GetIncomingList to Sync by default
* MM-15121 Migrate WebHook.GetIncomingList to Sync by default - add review changes
* Revert "SyncStore: migrate WebHooks.SaveIncoming method to Sync"
This reverts commit 626a7d1a25.
This commit is contained in:
committed by
Miguel de la Cruz
parent
105e8647f8
commit
357065e202
@@ -392,11 +392,7 @@ func (a *App) GetIncomingWebhooksPage(page, perPage int) ([]*model.IncomingWebho
|
||||
return nil, model.NewAppError("GetIncomingWebhooksPage", "api.incoming_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
if result := <-a.Srv.Store.Webhook().GetIncomingList(page*perPage, perPage); result.Err != nil {
|
||||
return nil, result.Err
|
||||
} else {
|
||||
return result.Data.([]*model.IncomingWebhook), nil
|
||||
}
|
||||
return a.Srv.Store.Webhook().GetIncomingList(page*perPage, perPage)
|
||||
}
|
||||
|
||||
func (a *App) CreateOutgoingWebhook(hook *model.OutgoingWebhook) (*model.OutgoingWebhook, *model.AppError) {
|
||||
|
||||
@@ -175,16 +175,15 @@ func (s SqlWebhookStore) PermanentDeleteIncomingByChannel(channelId string) stor
|
||||
})
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) GetIncomingList(offset, limit int) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
var webhooks []*model.IncomingWebhook
|
||||
func (s SqlWebhookStore) GetIncomingList(offset, limit int) ([]*model.IncomingWebhook, *model.AppError) {
|
||||
var webhooks []*model.IncomingWebhook
|
||||
|
||||
if _, err := s.GetReplica().Select(&webhooks, "SELECT * FROM IncomingWebhooks WHERE DeleteAt = 0 LIMIT :Limit OFFSET :Offset", map[string]interface{}{"Limit": limit, "Offset": offset}); err != nil {
|
||||
result.Err = model.NewAppError("SqlWebhookStore.GetIncomingList", "store.sql_webhooks.get_incoming_by_user.app_error", nil, "err="+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
if _, err := s.GetReplica().Select(&webhooks, "SELECT * FROM IncomingWebhooks WHERE DeleteAt = 0 LIMIT :Limit OFFSET :Offset", map[string]interface{}{"Limit": limit, "Offset": offset}); err != nil {
|
||||
return nil, model.NewAppError("SqlWebhookStore.GetIncomingList", "store.sql_webhooks.get_incoming_by_user.app_error", nil, "err="+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return webhooks, nil
|
||||
|
||||
result.Data = webhooks
|
||||
})
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) GetIncomingByTeam(teamId string, offset, limit int) ([]*model.IncomingWebhook, *model.AppError) {
|
||||
|
||||
@@ -379,7 +379,7 @@ type SystemStore interface {
|
||||
type WebhookStore interface {
|
||||
SaveIncoming(webhook *model.IncomingWebhook) (*model.IncomingWebhook, *model.AppError)
|
||||
GetIncoming(id string, allowFromCache bool) (*model.IncomingWebhook, *model.AppError)
|
||||
GetIncomingList(offset, limit int) StoreChannel
|
||||
GetIncomingList(offset, limit int) ([]*model.IncomingWebhook, *model.AppError)
|
||||
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)
|
||||
|
||||
@@ -158,19 +158,28 @@ func (_m *WebhookStore) GetIncomingByTeam(teamId string, offset int, limit int)
|
||||
}
|
||||
|
||||
// GetIncomingList provides a mock function with given fields: offset, limit
|
||||
func (_m *WebhookStore) GetIncomingList(offset int, limit int) store.StoreChannel {
|
||||
func (_m *WebhookStore) GetIncomingList(offset int, limit int) ([]*model.IncomingWebhook, *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.IncomingWebhook
|
||||
if rf, ok := ret.Get(0).(func(int, int) []*model.IncomingWebhook); ok {
|
||||
r0 = rf(offset, limit)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(store.StoreChannel)
|
||||
r0 = ret.Get(0).([]*model.IncomingWebhook)
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
// GetOutgoing provides a mock function with given fields: id
|
||||
|
||||
@@ -121,11 +121,10 @@ func testWebhookStoreGetIncomingList(t *testing.T, ss store.Store) {
|
||||
t.Fatal("unable to save webhook", err)
|
||||
}
|
||||
|
||||
if r1 := <-ss.Webhook().GetIncomingList(0, 1000); r1.Err != nil {
|
||||
t.Fatal(r1.Err)
|
||||
if hooks, err := ss.Webhook().GetIncomingList(0, 1000); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
found := false
|
||||
hooks := r1.Data.([]*model.IncomingWebhook)
|
||||
for _, hook := range hooks {
|
||||
if hook.Id == o1.Id {
|
||||
found = true
|
||||
@@ -136,10 +135,10 @@ func testWebhookStoreGetIncomingList(t *testing.T, ss store.Store) {
|
||||
}
|
||||
}
|
||||
|
||||
if result := <-ss.Webhook().GetIncomingList(0, 1); result.Err != nil {
|
||||
t.Fatal(result.Err)
|
||||
if hooks, err := ss.Webhook().GetIncomingList(0, 1); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
if len(result.Data.([]*model.IncomingWebhook)) != 1 {
|
||||
if len(hooks) != 1 {
|
||||
t.Fatal("only 1 should be returned")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user