[MM-55096] Introduce generic StoreResult (#25086)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
6dda6e3540
Коммит
b4c9eddca8
@@ -1401,18 +1401,18 @@ func (a *App) updateChannelMember(c request.CTX, member *model.ChannelMember) (*
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) DeleteChannel(c request.CTX, channel *model.Channel, userID string) *model.AppError {
|
func (a *App) DeleteChannel(c request.CTX, channel *model.Channel, userID string) *model.AppError {
|
||||||
ihc := make(chan store.StoreResult, 1)
|
ihc := make(chan store.GenericStoreResult[[]*model.IncomingWebhook], 1)
|
||||||
ohc := make(chan store.StoreResult, 1)
|
ohc := make(chan store.GenericStoreResult[[]*model.OutgoingWebhook], 1)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
webhooks, err := a.Srv().Store().Webhook().GetIncomingByChannel(channel.Id)
|
webhooks, err := a.Srv().Store().Webhook().GetIncomingByChannel(channel.Id)
|
||||||
ihc <- store.StoreResult{Data: webhooks, NErr: err}
|
ihc <- store.GenericStoreResult[[]*model.IncomingWebhook]{Data: webhooks, NErr: err}
|
||||||
close(ihc)
|
close(ihc)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
outgoingHooks, err := a.Srv().Store().Webhook().GetOutgoingByChannel(channel.Id, -1, -1)
|
outgoingHooks, err := a.Srv().Store().Webhook().GetOutgoingByChannel(channel.Id, -1, -1)
|
||||||
ohc <- store.StoreResult{Data: outgoingHooks, NErr: err}
|
ohc <- store.GenericStoreResult[[]*model.OutgoingWebhook]{Data: outgoingHooks, NErr: err}
|
||||||
close(ohc)
|
close(ohc)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@@ -1441,9 +1441,6 @@ func (a *App) DeleteChannel(c request.CTX, channel *model.Channel, userID string
|
|||||||
return model.NewAppError("DeleteChannel", "app.webhooks.get_outgoing_by_channel.app_error", nil, "", http.StatusInternalServerError).Wrap(ohcresult.NErr)
|
return model.NewAppError("DeleteChannel", "app.webhooks.get_outgoing_by_channel.app_error", nil, "", http.StatusInternalServerError).Wrap(ohcresult.NErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
incomingHooks := ihcresult.Data.([]*model.IncomingWebhook)
|
|
||||||
outgoingHooks := ohcresult.Data.([]*model.OutgoingWebhook)
|
|
||||||
|
|
||||||
if channel.DeleteAt > 0 {
|
if channel.DeleteAt > 0 {
|
||||||
err := model.NewAppError("deleteChannel", "api.channel.delete_channel.deleted.app_error", nil, "", http.StatusBadRequest)
|
err := model.NewAppError("deleteChannel", "api.channel.delete_channel.deleted.app_error", nil, "", http.StatusBadRequest)
|
||||||
return err
|
return err
|
||||||
@@ -1492,14 +1489,14 @@ func (a *App) DeleteChannel(c request.CTX, channel *model.Channel, userID string
|
|||||||
}
|
}
|
||||||
|
|
||||||
now := model.GetMillis()
|
now := model.GetMillis()
|
||||||
for _, hook := range incomingHooks {
|
for _, hook := range ihcresult.Data {
|
||||||
if err := a.Srv().Store().Webhook().DeleteIncoming(hook.Id, now); err != nil {
|
if err := a.Srv().Store().Webhook().DeleteIncoming(hook.Id, now); err != nil {
|
||||||
c.Logger().Warn("Encountered error deleting incoming webhook", mlog.String("hook_id", hook.Id), mlog.Err(err))
|
c.Logger().Warn("Encountered error deleting incoming webhook", mlog.String("hook_id", hook.Id), mlog.Err(err))
|
||||||
}
|
}
|
||||||
a.Srv().Platform().InvalidateCacheForWebhook(hook.Id)
|
a.Srv().Platform().InvalidateCacheForWebhook(hook.Id)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, hook := range outgoingHooks {
|
for _, hook := range ohcresult.Data {
|
||||||
if err := a.Srv().Store().Webhook().DeleteOutgoing(hook.Id, now); err != nil {
|
if err := a.Srv().Store().Webhook().DeleteOutgoing(hook.Id, now); err != nil {
|
||||||
c.Logger().Warn("Encountered error deleting outgoing webhook", mlog.String("hook_id", hook.Id), mlog.Err(err))
|
c.Logger().Warn("Encountered error deleting outgoing webhook", mlog.String("hook_id", hook.Id), mlog.Err(err))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import (
|
|||||||
"github.com/mattermost/mattermost/server/v8/channels/product"
|
"github.com/mattermost/mattermost/server/v8/channels/product"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Deprecated: Use GenericStoreResult instead.
|
||||||
type StoreResult struct {
|
type StoreResult struct {
|
||||||
Data any
|
Data any
|
||||||
|
|
||||||
@@ -22,6 +23,15 @@ type StoreResult struct {
|
|||||||
NErr error
|
NErr error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GenericStoreResult is a type safe version of StoreResult.
|
||||||
|
// Once all the code is migrated to use GenericStoreResult, it should be renamed to StoreResult.
|
||||||
|
type GenericStoreResult[T any] struct {
|
||||||
|
Data T
|
||||||
|
|
||||||
|
// NErr a temporary field used by the new code for the AppError migration. This will later become Err when the entire store is migrated.
|
||||||
|
NErr error
|
||||||
|
}
|
||||||
|
|
||||||
type Store interface {
|
type Store interface {
|
||||||
Team() TeamStore
|
Team() TeamStore
|
||||||
Channel() ChannelStore
|
Channel() ChannelStore
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user