mirror of
https://github.com/tulir/mautrix-whatsapp
synced 2024-12-13 09:03:10 +01:00
Increase length recently handled events array to 100
This commit is contained in:
parent
c888cb14a0
commit
c4ada14c2f
1 changed files with 6 additions and 4 deletions
10
portal.go
10
portal.go
|
@ -105,10 +105,12 @@ func (bridge *Bridge) NewPortal(dbPortal *database.Portal) *Portal {
|
|||
log: bridge.Log.Sub(fmt.Sprintf("Portal/%s", dbPortal.Key)),
|
||||
|
||||
messageLocks: make(map[types.WhatsAppMessageID]sync.Mutex),
|
||||
recentlyHandled: [20]types.WhatsAppMessageID{},
|
||||
recentlyHandled: [recentlyHandledLength]types.WhatsAppMessageID{},
|
||||
}
|
||||
}
|
||||
|
||||
const recentlyHandledLength = 100
|
||||
|
||||
type Portal struct {
|
||||
*database.Portal
|
||||
|
||||
|
@ -119,7 +121,7 @@ type Portal struct {
|
|||
messageLocksLock sync.Mutex
|
||||
messageLocks map[types.WhatsAppMessageID]sync.Mutex
|
||||
|
||||
recentlyHandled [20]types.WhatsAppMessageID
|
||||
recentlyHandled [recentlyHandledLength]types.WhatsAppMessageID
|
||||
recentlyHandledLock sync.Mutex
|
||||
recentlyHandledIndex uint8
|
||||
|
||||
|
@ -144,7 +146,7 @@ func (portal *Portal) deleteMessageLock(messageID types.WhatsAppMessageID) {
|
|||
|
||||
func (portal *Portal) isRecentlyHandled(id types.WhatsAppMessageID) bool {
|
||||
start := portal.recentlyHandledIndex
|
||||
for i := start; i != start; i = (i - 1) % 20 {
|
||||
for i := start; i != start; i = (i - 1) % recentlyHandledLength {
|
||||
if portal.recentlyHandled[i] == id {
|
||||
return true
|
||||
}
|
||||
|
@ -184,7 +186,7 @@ func (portal *Portal) markHandled(source *User, message *waProto.WebMessageInfo,
|
|||
|
||||
portal.recentlyHandledLock.Lock()
|
||||
index := portal.recentlyHandledIndex
|
||||
portal.recentlyHandledIndex = (portal.recentlyHandledIndex + 1) % 20
|
||||
portal.recentlyHandledIndex = (portal.recentlyHandledIndex + 1) % recentlyHandledLength
|
||||
portal.recentlyHandledLock.Unlock()
|
||||
portal.recentlyHandled[index] = msg.JID
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue