Memory Leak in Cooldown System #2
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
ask_cooldowns = {} # Line 558
Issue: Dictionary grows indefinitely, never removes old entries.
Fix:
from collections import defaultdict
from datetime import datetime, timedelta
class CooldownManager:
def init(self, minutes: int):
self.cooldowns = {}
self.duration = timedelta(minutes=minutes)
Usage:
ask_cooldown_manager = CooldownManager(COOLDOWN_MINUTES)