mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-04-22 16:51:59 +00:00
Fix cache eviction for ratelimit objects
This commit is contained in:
parent
54ee383585
commit
8dd186cf1e
@ -335,6 +335,7 @@ class Ratelimit:
|
||||
'reset_after',
|
||||
'expires',
|
||||
'dirty',
|
||||
'_last_request',
|
||||
'_max_ratelimit_timeout',
|
||||
'_loop',
|
||||
'_pending_requests',
|
||||
@ -355,6 +356,7 @@ class Ratelimit:
|
||||
# The object that is sleeping is ultimately responsible for freeing the semaphore
|
||||
# for the requests currently pending.
|
||||
self._sleeping: asyncio.Lock = asyncio.Lock()
|
||||
self._last_request: float = self._loop.time()
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return (
|
||||
@ -422,7 +424,12 @@ class Ratelimit:
|
||||
def is_expired(self) -> bool:
|
||||
return self.expires is not None and self._loop.time() > self.expires
|
||||
|
||||
def is_inactive(self) -> bool:
|
||||
delta = self._loop.time() - self._last_request
|
||||
return delta >= 300 and self.outgoing == 0 and len(self._pending_requests) == 0
|
||||
|
||||
async def acquire(self) -> None:
|
||||
self._last_request = self._loop.time()
|
||||
if self.is_expired():
|
||||
self.reset()
|
||||
|
||||
@ -532,7 +539,7 @@ class HTTPClient:
|
||||
if len(self._buckets) < 256:
|
||||
return
|
||||
|
||||
keys = [key for key, bucket in self._buckets.items() if bucket.is_expired()]
|
||||
keys = [key for key, bucket in self._buckets.items() if bucket.is_inactive()]
|
||||
for key in keys:
|
||||
del self._buckets[key]
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user