From ecff37e080cb2373f2fb611eff2d629cc211de4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Mon, 13 Nov 2023 15:11:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=AE=A1=E6=95=B0=E5=99=A8?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/utils/counters/counter.go | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/internal/utils/counters/counter.go b/internal/utils/counters/counter.go index bef8238..52a7515 100644 --- a/internal/utils/counters/counter.go +++ b/internal/utils/counters/counter.go @@ -66,19 +66,16 @@ func (this *Counter) Increase(key uint64, lifeSeconds int) uint64 { var index = int(key % this.countMaps) this.locker.RLock(index) var item = this.itemMaps[index][key] + var l = len(this.itemMaps[index]) this.locker.RUnlock(index) if item == nil { // no need to care about duplication - item = NewItem(lifeSeconds) - this.locker.Lock(index) - - // check again - oldItem, ok := this.itemMaps[index][key] - if !ok { - this.itemMaps[index][key] = item - } else { - item = oldItem + if l > maxItemsPerGroup { + return 1 } + item = NewItem(lifeSeconds) + this.locker.Lock(index) + this.itemMaps[index][key] = item this.locker.Unlock(index) }