Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions bridge/discord/discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"sync"

"github.com/bwmarrin/discordgo"
lru "github.com/hashicorp/golang-lru"
lru "github.com/hashicorp/golang-lru/v2"
"github.com/matterbridge-org/matterbridge/bridge"
"github.com/matterbridge-org/matterbridge/bridge/config"
"github.com/matterbridge-org/matterbridge/bridge/discord/transmitter"
Expand Down Expand Up @@ -39,11 +39,11 @@ type Bdiscord struct {
// Webhook specific logic
useAutoWebhooks bool
transmitter *transmitter.Transmitter
cache *lru.Cache
cache *lru.Cache[string, string]
}

func New(cfg *bridge.Config) bridge.Bridger {
newCache, err := lru.New(5000)
newCache, err := lru.New[string, string](5000)
if err != nil {
cfg.Log.Fatalf("Could not create LRU cache: %v", err)
}
Expand Down Expand Up @@ -320,7 +320,7 @@ func (b *Bdiscord) handleEventBotUser(msg *config.Message, channelID string) (st
}

if fi, ok := b.cache.Get(cFileUpload + msg.ID); ok {
err := b.c.ChannelMessageDelete(channelID, fi.(string)) // nolint:forcetypeassert
err := b.c.ChannelMessageDelete(channelID, fi)
b.cache.Remove(cFileUpload + msg.ID)
return "", err
}
Expand Down
6 changes: 3 additions & 3 deletions bridge/rocketchat/rocketchat.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strings"
"sync"

lru "github.com/hashicorp/golang-lru"
lru "github.com/hashicorp/golang-lru/v2"
"github.com/matterbridge-org/matterbridge/bridge"
"github.com/matterbridge-org/matterbridge/bridge/config"
"github.com/matterbridge-org/matterbridge/bridge/helper"
Expand All @@ -22,7 +22,7 @@ type Brocketchat struct {
rh *rockethook.Client
c *realtime.Client
r *rest.Client
cache *lru.Cache
cache *lru.Cache[string, bool]
*bridge.Config
messageChan chan models.Message
channelMap map[string]string
Expand All @@ -37,7 +37,7 @@ const (
)

func New(cfg *bridge.Config) bridge.Bridger {
newCache, err := lru.New(100)
newCache, err := lru.New[string, bool](100)
if err != nil {
cfg.Log.Fatalf("Could not create LRU cache for rocketchat bridge: %v", err)
}
Expand Down
6 changes: 3 additions & 3 deletions bridge/slack/slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"sync"
"time"

lru "github.com/hashicorp/golang-lru"
lru "github.com/hashicorp/golang-lru/v2"
"github.com/matterbridge-org/matterbridge/bridge"
"github.com/matterbridge-org/matterbridge/bridge/config"
"github.com/matterbridge-org/matterbridge/bridge/helper"
Expand All @@ -36,7 +36,7 @@ type Bslack struct {
actingUserID string
actingUserName string

cache *lru.Cache
cache *lru.Cache[string, any]
uuid string
useChannelID bool

Expand Down Expand Up @@ -103,7 +103,7 @@ func New(cfg *bridge.Config) bridge.Bridger {
}

func newBridge(cfg *bridge.Config) *Bslack {
newCache, err := lru.New(5000)
newCache, err := lru.New[string, any](5000)
if err != nil {
cfg.Log.Fatalf("Could not create LRU cache for Slack bridge: %v", err)
}
Expand Down
21 changes: 6 additions & 15 deletions gateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"github.com/d5/tengo/v2"
"github.com/d5/tengo/v2/stdlib"
lru "github.com/hashicorp/golang-lru"
lru "github.com/hashicorp/golang-lru/v2"
"github.com/kyokomi/emoji/v2"
"github.com/matterbridge-org/matterbridge/bridge"
"github.com/matterbridge-org/matterbridge/bridge/config"
Expand All @@ -29,7 +29,7 @@ type Gateway struct {
ChannelOptions map[string]config.ChannelOptions
Message chan config.Message
Name string
Messages *lru.Cache
Messages *lru.Cache[string, []*BrMsgID]

logger *logrus.Entry
}
Expand Down Expand Up @@ -105,18 +105,10 @@ func (gw *Gateway) FindCanonicalMsgID(protocol string, mID string) string {

// If not keyed, iterate through cache for downstream, and infer upstream.
for _, mid := range gw.Messages.Keys() {
v, _ := gw.Messages.Peek(mid)
ids, ok := v.([]*BrMsgID)
if !ok { // type assertion failed
gw.logger.Errorf("v.([]*BrMsgID) type assertion failed")
}
ids, _ := gw.Messages.Peek(mid)
for _, downstreamMsgObj := range ids {
if ID == downstreamMsgObj.ID {
midstring, ok := mid.(string)
if !ok { // type assertion failed
gw.logger.Errorf("mid.(string) type assertion failed")
}
return midstring
return mid
}
}
}
Expand All @@ -128,7 +120,7 @@ func (gw *Gateway) FindCanonicalMsgID(protocol string, mID string) string {
func New(rootLogger *logrus.Logger, cfg *config.Gateway, r *Router) *Gateway {
logger := rootLogger.WithFields(logrus.Fields{"prefix": "gateway"})

cache, _ := lru.New(5000)
cache, _ := lru.New[string, []*BrMsgID](5000)
gw := &Gateway{
Channels: make(map[string]*config.ChannelInfo),
Message: r.Message,
Expand Down Expand Up @@ -389,8 +381,7 @@ func (gw *Gateway) getDestChannel(msg *config.Message, dest bridge.Bridge) []con
}

func (gw *Gateway) getDestMsgID(msgID string, dest *bridge.Bridge, channel *config.ChannelInfo) string {
if res, ok := gw.Messages.Get(msgID); ok {
IDs := res.([]*BrMsgID)
if IDs, ok := gw.Messages.Get(msgID); ok {
for _, id := range IDs {
// check protocol, bridge name and channelname
// for people that reuse the same bridge multiple times. see #342
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/fsnotify/fsnotify v1.7.0
github.com/google/gops v0.3.27
github.com/gorilla/schema v1.4.1
github.com/hashicorp/golang-lru v1.0.2
github.com/hashicorp/golang-lru/v2 v2.0.7
github.com/jpillora/backoff v1.0.0
github.com/kyokomi/emoji/v2 v2.2.13
github.com/labstack/echo/v4 v4.12.0
Expand Down Expand Up @@ -76,7 +76,7 @@ require (
github.com/hashicorp/go-hclog v1.6.3 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-plugin v1.6.1 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/yamux v0.1.1 // indirect
github.com/kettek/apng v0.0.0-20191108220231-414630eed80f // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+l
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/hashicorp/go-plugin v1.6.1 h1:P7MR2UP6gNKGPp+y7EZw2kOiq4IR9WiqLvp0XOsVdwI=
github.com/hashicorp/go-plugin v1.6.1/go.mod h1:XPHFku2tFo3o3QKFgSYo+cghcUhw1NA1hZyMK0PWAw0=
github.com/hashicorp/golang-lru v1.0.2 h1:dV3g9Z/unq5DpblPpw+Oqcv4dU/1omnb4Ok8iPY6p1c=
github.com/hashicorp/golang-lru v1.0.2/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc=
github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k=
github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
Expand Down
Loading