[MM-15122] Migrate "WebHook.GetIncomingByTeam" to Sync by default (#10631)

Этот коммит содержится в:
Siyuan Liu
2019-04-22 08:29:55 -07:00
коммит произвёл Jesse Hallam
родитель 1e92646646
Коммит 434f343f69
6 изменённых файлов: 35 добавлений и 26 удалений

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

@@ -388,11 +388,7 @@ func (a *App) GetIncomingWebhooksForTeamPage(teamId string, page, perPage int) (
return nil, model.NewAppError("GetIncomingWebhooksForTeamPage", "api.incoming_webhook.disabled.app_error", nil, "", http.StatusNotImplemented) return nil, model.NewAppError("GetIncomingWebhooksForTeamPage", "api.incoming_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
} }
if result := <-a.Srv.Store.Webhook().GetIncomingByTeam(teamId, page*perPage, perPage); result.Err != nil { return a.Srv.Store.Webhook().GetIncomingByTeam(teamId, page*perPage, perPage)
return nil, result.Err
} else {
return result.Data.([]*model.IncomingWebhook), nil
}
} }
func (a *App) GetIncomingWebhooksPage(page, perPage int) ([]*model.IncomingWebhook, *model.AppError) { func (a *App) GetIncomingWebhooksPage(page, perPage int) ([]*model.IncomingWebhook, *model.AppError) {

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

@@ -8,6 +8,7 @@ import (
"strings" "strings"
"github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/model"
"github.com/mattermost/mattermost-server/store"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@@ -101,7 +102,12 @@ func listWebhookCmdF(command *cobra.Command, args []string) error {
} }
// Fetch all hooks with a very large limit so we get them all. // Fetch all hooks with a very large limit so we get them all.
incomingResult := app.Srv.Store.Webhook().GetIncomingByTeam(team.Id, 0, 100000000) incomingResult := make(chan store.StoreResult, 1)
go func() {
incomingHooks, err := app.Srv.Store.Webhook().GetIncomingByTeam(team.Id, 0, 100000000)
incomingResult <- store.StoreResult{Data: incomingHooks, Err: err}
close(incomingResult)
}()
outgoingResult := app.Srv.Store.Webhook().GetOutgoingByTeam(team.Id, 0, 100000000) outgoingResult := app.Srv.Store.Webhook().GetOutgoingByTeam(team.Id, 0, 100000000)
if result := <-incomingResult; result.Err == nil { if result := <-incomingResult; result.Err == nil {

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

@@ -188,16 +188,14 @@ func (s SqlWebhookStore) GetIncomingList(offset, limit int) store.StoreChannel {
}) })
} }
func (s SqlWebhookStore) GetIncomingByTeam(teamId string, offset, limit int) store.StoreChannel { func (s SqlWebhookStore) GetIncomingByTeam(teamId string, offset, limit int) ([]*model.IncomingWebhook, *model.AppError) {
return store.Do(func(result *store.StoreResult) { var webhooks []*model.IncomingWebhook
var webhooks []*model.IncomingWebhook
if _, err := s.GetReplica().Select(&webhooks, "SELECT * FROM IncomingWebhooks WHERE TeamId = :TeamId AND DeleteAt = 0 LIMIT :Limit OFFSET :Offset", map[string]interface{}{"TeamId": teamId, "Limit": limit, "Offset": offset}); err != nil { if _, err := s.GetReplica().Select(&webhooks, "SELECT * FROM IncomingWebhooks WHERE TeamId = :TeamId AND DeleteAt = 0 LIMIT :Limit OFFSET :Offset", map[string]interface{}{"TeamId": teamId, "Limit": limit, "Offset": offset}); err != nil {
result.Err = model.NewAppError("SqlWebhookStore.GetIncomingByUser", "store.sql_webhooks.get_incoming_by_user.app_error", nil, "teamId="+teamId+", err="+err.Error(), http.StatusInternalServerError) return nil, model.NewAppError("SqlWebhookStore.GetIncomingByUser", "store.sql_webhooks.get_incoming_by_user.app_error", nil, "teamId="+teamId+", err="+err.Error(), http.StatusInternalServerError)
} }
result.Data = webhooks return webhooks, nil
})
} }
func (s SqlWebhookStore) GetIncomingByChannel(channelId string) ([]*model.IncomingWebhook, *model.AppError) { func (s SqlWebhookStore) GetIncomingByChannel(channelId string) ([]*model.IncomingWebhook, *model.AppError) {

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

@@ -380,7 +380,7 @@ type WebhookStore interface {
SaveIncoming(webhook *model.IncomingWebhook) StoreChannel SaveIncoming(webhook *model.IncomingWebhook) StoreChannel
GetIncoming(id string, allowFromCache bool) (*model.IncomingWebhook, *model.AppError) GetIncoming(id string, allowFromCache bool) (*model.IncomingWebhook, *model.AppError)
GetIncomingList(offset, limit int) StoreChannel GetIncomingList(offset, limit int) StoreChannel
GetIncomingByTeam(teamId string, offset, limit int) StoreChannel GetIncomingByTeam(teamId string, offset, limit int) ([]*model.IncomingWebhook, *model.AppError)
UpdateIncoming(webhook *model.IncomingWebhook) (*model.IncomingWebhook, *model.AppError) UpdateIncoming(webhook *model.IncomingWebhook) (*model.IncomingWebhook, *model.AppError)
GetIncomingByChannel(channelId string) ([]*model.IncomingWebhook, *model.AppError) GetIncomingByChannel(channelId string) ([]*model.IncomingWebhook, *model.AppError)
DeleteIncoming(webhookId string, time int64) StoreChannel DeleteIncoming(webhookId string, time int64) StoreChannel

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

@@ -133,19 +133,28 @@ func (_m *WebhookStore) GetIncomingByChannel(channelId string) ([]*model.Incomin
} }
// GetIncomingByTeam provides a mock function with given fields: teamId, offset, limit // GetIncomingByTeam provides a mock function with given fields: teamId, offset, limit
func (_m *WebhookStore) GetIncomingByTeam(teamId string, offset int, limit int) store.StoreChannel { func (_m *WebhookStore) GetIncomingByTeam(teamId string, offset int, limit int) ([]*model.IncomingWebhook, *model.AppError) {
ret := _m.Called(teamId, offset, limit) ret := _m.Called(teamId, offset, limit)
var r0 store.StoreChannel var r0 []*model.IncomingWebhook
if rf, ok := ret.Get(0).(func(string, int, int) store.StoreChannel); ok { if rf, ok := ret.Get(0).(func(string, int, int) []*model.IncomingWebhook); ok {
r0 = rf(teamId, offset, limit) r0 = rf(teamId, 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.IncomingWebhook)
} }
} }
return r0 var r1 *model.AppError
if rf, ok := ret.Get(1).(func(string, int, int) *model.AppError); ok {
r1 = rf(teamId, offset, limit)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
}
return r0, r1
} }
// GetIncomingList provides a mock function with given fields: offset, limit // GetIncomingList provides a mock function with given fields: offset, limit

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

@@ -134,18 +134,18 @@ func testWebhookStoreGetIncomingByTeam(t *testing.T, ss store.Store) {
o1 = (<-ss.Webhook().SaveIncoming(o1)).Data.(*model.IncomingWebhook) o1 = (<-ss.Webhook().SaveIncoming(o1)).Data.(*model.IncomingWebhook)
if r1 := <-ss.Webhook().GetIncomingByTeam(o1.TeamId, 0, 100); r1.Err != nil { if hooks, err := ss.Webhook().GetIncomingByTeam(o1.TeamId, 0, 100); err != nil {
t.Fatal(r1.Err) t.Fatal(err)
} else { } else {
if r1.Data.([]*model.IncomingWebhook)[0].CreateAt != o1.CreateAt { if hooks[0].CreateAt != o1.CreateAt {
t.Fatal("invalid returned webhook") t.Fatal("invalid returned webhook")
} }
} }
if result := <-ss.Webhook().GetIncomingByTeam("123", 0, 100); result.Err != nil { if hooks, err := ss.Webhook().GetIncomingByTeam("123", 0, 100); err != nil {
t.Fatal(result.Err) t.Fatal(err)
} else { } else {
if len(result.Data.([]*model.IncomingWebhook)) != 0 { if len(hooks) != 0 {
t.Fatal("no webhooks should have returned") t.Fatal("no webhooks should have returned")
} }
} }