From c4ada14c2fe0a679c58d3516fd7cb813b22e3c6a Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sun, 2 Sep 2018 00:01:22 +0300 Subject: [PATCH] Increase length recently handled events array to 100 --- portal.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/portal.go b/portal.go index d619dea..a538e31 100644 --- a/portal.go +++ b/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 }