Remove support for unused product interfaces (#24965)
We no longer rely on commands and hooks for products, so simplify this code.
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
1de790a4fe
Коммит
2ba91e43b6
@@ -226,14 +226,6 @@ type FrontendService interface {
|
||||
OpenInteractiveDialog(dialog model.OpenDialogRequest) *model.AppError
|
||||
}
|
||||
|
||||
// CommandService is the API for interacting with front end.
|
||||
//
|
||||
// The service shall be registered via app.CommandKey service key.
|
||||
type CommandService interface {
|
||||
ExecuteCommand(c request.CTX, args *model.CommandArgs) (*model.CommandResponse, *model.AppError)
|
||||
RegisterProductCommand(productID string, command *model.Command) error
|
||||
}
|
||||
|
||||
// ThreadsService is the API for interacting with threads anywhere.
|
||||
//
|
||||
// The service shall be registered via app.ThreadsKey service key.
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package product
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/plugin"
|
||||
"github.com/mattermost/mattermost/server/v8/einterfaces"
|
||||
)
|
||||
|
||||
type HooksManager struct {
|
||||
registeredProducts sync.Map
|
||||
metrics einterfaces.MetricsInterface
|
||||
}
|
||||
|
||||
func NewHooksManager(metrics einterfaces.MetricsInterface) *HooksManager {
|
||||
return &HooksManager{
|
||||
metrics: metrics,
|
||||
}
|
||||
}
|
||||
|
||||
func (m *HooksManager) AddProduct(productID string, hooks any) error {
|
||||
prod, err := plugin.NewAdapter(hooks)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
rp := &plugin.RegisteredProduct{
|
||||
ProductID: productID,
|
||||
Adapter: prod,
|
||||
}
|
||||
|
||||
m.registeredProducts.Store(productID, rp)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *HooksManager) RemoveProduct(productID string) {
|
||||
m.registeredProducts.Delete(productID)
|
||||
}
|
||||
|
||||
func (m *HooksManager) RunMultiHook(hookRunnerFunc func(hooks plugin.Hooks) bool, hookId int) {
|
||||
startTime := time.Now()
|
||||
|
||||
m.registeredProducts.Range(func(key, value any) bool {
|
||||
rp := value.(*plugin.RegisteredProduct)
|
||||
|
||||
if !rp.Implements(hookId) {
|
||||
return true
|
||||
}
|
||||
|
||||
hookStartTime := time.Now()
|
||||
result := hookRunnerFunc(rp.Adapter)
|
||||
|
||||
if m.metrics != nil {
|
||||
elapsedTime := float64(time.Since(hookStartTime)) / float64(time.Second)
|
||||
m.metrics.ObservePluginMultiHookIterationDuration(rp.ProductID, elapsedTime)
|
||||
}
|
||||
|
||||
return result
|
||||
})
|
||||
|
||||
if m.metrics != nil {
|
||||
elapsedTime := float64(time.Since(startTime)) / float64(time.Second)
|
||||
m.metrics.ObservePluginMultiHookDuration(elapsedTime)
|
||||
}
|
||||
}
|
||||
|
||||
func (m *HooksManager) HooksForProduct(id string) plugin.Hooks {
|
||||
if value, ok := m.registeredProducts.Load(id); ok {
|
||||
rp := value.(*plugin.RegisteredProduct)
|
||||
return rp.Adapter
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -21,7 +21,6 @@ const (
|
||||
RouterKey ServiceKey = "router"
|
||||
BotKey ServiceKey = "bot"
|
||||
LogKey ServiceKey = "log"
|
||||
HooksKey ServiceKey = "hooks"
|
||||
KVStoreKey ServiceKey = "kvstore"
|
||||
StoreKey ServiceKey = "storekey"
|
||||
SystemKey ServiceKey = "systemkey"
|
||||
|
||||
Ссылка в новой задаче
Block a user