GH-10617 SyncStore: GetIncomingByChannel to sync (#10633)
* GH-10617 GetIncomingByChannel to sync * GH-10617 using async calls explicitly * GH-10617 order of assignment change * Update store.go * Update store.go * Update store.go * GH-10617 fmt fix
Этот коммит содержится в:
коммит произвёл
Jesse Hallam
родитель
99a8370742
Коммит
1e92646646
@@ -766,8 +766,13 @@ func (a *App) UpdateChannelMemberNotifyProps(data map[string]string, channelId s
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) DeleteChannel(channel *model.Channel, userId string) *model.AppError {
|
func (a *App) DeleteChannel(channel *model.Channel, userId string) *model.AppError {
|
||||||
ihc := a.Srv.Store.Webhook().GetIncomingByChannel(channel.Id)
|
ihc := make(chan store.StoreResult, 1)
|
||||||
ohc := a.Srv.Store.Webhook().GetOutgoingByChannel(channel.Id, -1, -1)
|
ohc := a.Srv.Store.Webhook().GetOutgoingByChannel(channel.Id, -1, -1)
|
||||||
|
go func() {
|
||||||
|
webhooks, err := a.Srv.Store.Webhook().GetIncomingByChannel(channel.Id)
|
||||||
|
ihc <- store.StoreResult{Data: webhooks, Err: err}
|
||||||
|
close(ihc)
|
||||||
|
}()
|
||||||
|
|
||||||
var user *model.User
|
var user *model.User
|
||||||
if userId != "" {
|
if userId != "" {
|
||||||
|
|||||||
@@ -4,9 +4,8 @@
|
|||||||
package sqlstore
|
package sqlstore
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/einterfaces"
|
"github.com/mattermost/mattermost-server/einterfaces"
|
||||||
"github.com/mattermost/mattermost-server/model"
|
"github.com/mattermost/mattermost-server/model"
|
||||||
@@ -201,16 +200,14 @@ func (s SqlWebhookStore) GetIncomingByTeam(teamId string, offset, limit int) sto
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SqlWebhookStore) GetIncomingByChannel(channelId string) store.StoreChannel {
|
func (s SqlWebhookStore) GetIncomingByChannel(channelId string) ([]*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 ChannelId = :ChannelId AND DeleteAt = 0", map[string]interface{}{"ChannelId": channelId}); err != nil {
|
if _, err := s.GetReplica().Select(&webhooks, "SELECT * FROM IncomingWebhooks WHERE ChannelId = :ChannelId AND DeleteAt = 0", map[string]interface{}{"ChannelId": channelId}); err != nil {
|
||||||
result.Err = model.NewAppError("SqlWebhookStore.GetIncomingByChannel", "store.sql_webhooks.get_incoming_by_channel.app_error", nil, "channelId="+channelId+", err="+err.Error(), http.StatusInternalServerError)
|
return nil, model.NewAppError("SqlWebhookStore.GetIncomingByChannel", "store.sql_webhooks.get_incoming_by_channel.app_error", nil, "channelId="+channelId+", err="+err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
result.Data = webhooks
|
return webhooks, nil
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SqlWebhookStore) SaveOutgoing(webhook *model.OutgoingWebhook) store.StoreChannel {
|
func (s SqlWebhookStore) SaveOutgoing(webhook *model.OutgoingWebhook) store.StoreChannel {
|
||||||
|
|||||||
@@ -382,7 +382,7 @@ type WebhookStore interface {
|
|||||||
GetIncomingList(offset, limit int) StoreChannel
|
GetIncomingList(offset, limit int) StoreChannel
|
||||||
GetIncomingByTeam(teamId string, offset, limit int) StoreChannel
|
GetIncomingByTeam(teamId string, offset, limit int) StoreChannel
|
||||||
UpdateIncoming(webhook *model.IncomingWebhook) (*model.IncomingWebhook, *model.AppError)
|
UpdateIncoming(webhook *model.IncomingWebhook) (*model.IncomingWebhook, *model.AppError)
|
||||||
GetIncomingByChannel(channelId string) StoreChannel
|
GetIncomingByChannel(channelId string) ([]*model.IncomingWebhook, *model.AppError)
|
||||||
DeleteIncoming(webhookId string, time int64) StoreChannel
|
DeleteIncoming(webhookId string, time int64) StoreChannel
|
||||||
PermanentDeleteIncomingByChannel(channelId string) StoreChannel
|
PermanentDeleteIncomingByChannel(channelId string) StoreChannel
|
||||||
PermanentDeleteIncomingByUser(userId string) StoreChannel
|
PermanentDeleteIncomingByUser(userId string) StoreChannel
|
||||||
|
|||||||
@@ -108,19 +108,28 @@ func (_m *WebhookStore) GetIncoming(id string, allowFromCache bool) (*model.Inco
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetIncomingByChannel provides a mock function with given fields: channelId
|
// GetIncomingByChannel provides a mock function with given fields: channelId
|
||||||
func (_m *WebhookStore) GetIncomingByChannel(channelId string) store.StoreChannel {
|
func (_m *WebhookStore) GetIncomingByChannel(channelId string) ([]*model.IncomingWebhook, *model.AppError) {
|
||||||
ret := _m.Called(channelId)
|
ret := _m.Called(channelId)
|
||||||
|
|
||||||
var r0 store.StoreChannel
|
var r0 []*model.IncomingWebhook
|
||||||
if rf, ok := ret.Get(0).(func(string) store.StoreChannel); ok {
|
if rf, ok := ret.Get(0).(func(string) []*model.IncomingWebhook); ok {
|
||||||
r0 = rf(channelId)
|
r0 = rf(channelId)
|
||||||
} 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) *model.AppError); ok {
|
||||||
|
r1 = rf(channelId)
|
||||||
|
} else {
|
||||||
|
if ret.Get(1) != nil {
|
||||||
|
r1 = ret.Get(1).(*model.AppError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetIncomingByTeam provides a mock function with given fields: teamId, offset, limit
|
// GetIncomingByTeam provides a mock function with given fields: teamId, offset, limit
|
||||||
|
|||||||
@@ -4,11 +4,10 @@
|
|||||||
package storetest
|
package storetest
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/model"
|
"github.com/mattermost/mattermost-server/model"
|
||||||
"github.com/mattermost/mattermost-server/store"
|
"github.com/mattermost/mattermost-server/store"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
@@ -152,6 +151,26 @@ func testWebhookStoreGetIncomingByTeam(t *testing.T, ss store.Store) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testWebhookStoreGetIncomingByChannel(t *testing.T, ss store.Store) {
|
||||||
|
o1 := buildIncomingWebhook()
|
||||||
|
|
||||||
|
o1 = (<-ss.Webhook().SaveIncoming(o1)).Data.(*model.IncomingWebhook)
|
||||||
|
|
||||||
|
webhooks, err := ss.Webhook().GetIncomingByChannel(o1.ChannelId)
|
||||||
|
require.Nil(t, err)
|
||||||
|
if webhooks[0].CreateAt != o1.CreateAt {
|
||||||
|
t.Fatal("invalid returned webhook")
|
||||||
|
}
|
||||||
|
|
||||||
|
if webhooks, err = ss.Webhook().GetIncomingByChannel("123"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
} else {
|
||||||
|
if len(webhooks) != 0 {
|
||||||
|
t.Fatal("no webhooks should have returned")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func testWebhookStoreDeleteIncoming(t *testing.T, ss store.Store) {
|
func testWebhookStoreDeleteIncoming(t *testing.T, ss store.Store) {
|
||||||
o1 := buildIncomingWebhook()
|
o1 := buildIncomingWebhook()
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user