MCPcopy Create free account
hub / github.com/aiprodcoder/MIXAPI / checkMemoryLimit

Function checkMemoryLimit

service/notify-limit.go:88–117  ·  view source on GitHub ↗
(userId int, notifyType string)

Source from the content-addressed store, hash-verified

86}
87
88func 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}

Callers 1

CheckNotificationLimitFunction · 0.85

Calls 1

getDurationFunction · 0.85

Tested by

no test coverage detected