(userId int, notifyType string)
| 86 | } |
| 87 | |
| 88 | func checkMemoryLimit(userId int, notifyType string) (bool, error) { |
| 89 | // Ensure cleanup task is started |
| 90 | cleanupOnce.Do(startCleanupTask) |
| 91 | |
| 92 | key := fmt.Sprintf("%d:%s:%s", userId, notifyType, time.Now().Format("2006010215")) |
| 93 | now := time.Now() |
| 94 | |
| 95 | // Get current limit count or initialize new one |
| 96 | var currentLimit limitCount |
| 97 | if value, ok := notifyLimitStore.Load(key); ok { |
| 98 | currentLimit = value.(limitCount) |
| 99 | // Check if the entry has expired |
| 100 | if now.Sub(currentLimit.Timestamp) >= getDuration() { |
| 101 | currentLimit = limitCount{Count: 0, Timestamp: now} |
| 102 | } |
| 103 | } else { |
| 104 | currentLimit = limitCount{Count: 0, Timestamp: now} |
| 105 | } |
| 106 | |
| 107 | // Increment count |
| 108 | currentLimit.Count++ |
| 109 | |
| 110 | // Check against limits |
| 111 | limit := constant.NotifyLimitCount |
| 112 | |
| 113 | // Store updated count |
| 114 | notifyLimitStore.Store(key, currentLimit) |
| 115 | |
| 116 | return currentLimit.Count <= limit, nil |
| 117 | } |
no test coverage detected