GH-10652: Migrate WebHookStore.GetOutgoingList method to sync by default (#10703)

* Migrate WebHookStore.GetOutgoingList  method to sync by default

* go fmt the code
Этот коммит содержится в:
Puneeth Reddy
2019-04-25 22:41:45 -07:00
коммит произвёл Jesús Espino
родитель f7982216e4
Коммит 9fc05b5865
5 изменённых файлов: 28 добавлений и 25 удалений

Просмотреть файл

@@ -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) 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 a.Srv.Store.Webhook().GetOutgoingList(page*perPage, perPage)
return nil, result.Err
} else {
return result.Data.([]*model.OutgoingWebhook), nil
}
} }
func (a *App) GetOutgoingWebhooksForChannelPage(channelId string, page, perPage int) ([]*model.OutgoingWebhook, *model.AppError) { 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 return &webhook, nil
} }
func (s SqlWebhookStore) GetOutgoingList(offset, limit int) store.StoreChannel { func (s SqlWebhookStore) GetOutgoingList(offset, limit int) ([]*model.OutgoingWebhook, *model.AppError) {
return store.Do(func(result *store.StoreResult) { var webhooks []*model.OutgoingWebhook
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 { 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) 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 { 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) SaveOutgoing(webhook *model.OutgoingWebhook) (*model.OutgoingWebhook, *model.AppError)
GetOutgoing(id string) (*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 GetOutgoingByChannel(channelId string, offset, limit int) StoreChannel
GetOutgoingByTeam(teamId string, offset, limit int) StoreChannel GetOutgoingByTeam(teamId string, offset, limit int) StoreChannel
DeleteOutgoing(webhookId string, time int64) 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 // 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) ret := _m.Called(offset, limit)
var r0 store.StoreChannel var r0 []*model.OutgoingWebhook
if rf, ok := ret.Get(0).(func(int, int) store.StoreChannel); ok { if rf, ok := ret.Get(0).(func(int, int) []*model.OutgoingWebhook); ok {
r0 = rf(offset, limit) r0 = rf(offset, limit)
} else { } else {
if ret.Get(0) != nil { 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 // 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) o2, _ = ss.Webhook().SaveOutgoing(o2)
if r1 := <-ss.Webhook().GetOutgoingList(0, 1000); r1.Err != nil { if r1, err := ss.Webhook().GetOutgoingList(0, 1000); err != nil {
t.Fatal(r1.Err) t.Fatal(err)
} else { } else {
hooks := r1.Data.([]*model.OutgoingWebhook) hooks := r1
found1 := false found1 := false
found2 := 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 { if result, err := ss.Webhook().GetOutgoingList(0, 2); err != nil {
t.Fatal(result.Err) t.Fatal(err)
} else { } else {
if len(result.Data.([]*model.OutgoingWebhook)) != 2 { if len(result) != 2 {
t.Fatal("wrong number of hooks returned") t.Fatal("wrong number of hooks returned")
} }
} }