Increase length recently handled events array to 100

This commit is contained in:
Tulir Asokan 2018-09-02 00:01:22 +03:00
parent c888cb14a0
commit c4ada14c2f

View file

@ -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
}