mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-06-08 04:38:42 +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',
|
'reset_after',
|
||||||
'expires',
|
'expires',
|
||||||
'dirty',
|
'dirty',
|
||||||
|
'_last_request',
|
||||||
'_max_ratelimit_timeout',
|
'_max_ratelimit_timeout',
|
||||||
'_loop',
|
'_loop',
|
||||||
'_pending_requests',
|
'_pending_requests',
|
||||||
@ -355,6 +356,7 @@ class Ratelimit:
|
|||||||
# The object that is sleeping is ultimately responsible for freeing the semaphore
|
# The object that is sleeping is ultimately responsible for freeing the semaphore
|
||||||
# for the requests currently pending.
|
# for the requests currently pending.
|
||||||
self._sleeping: asyncio.Lock = asyncio.Lock()
|
self._sleeping: asyncio.Lock = asyncio.Lock()
|
||||||
|
self._last_request: float = self._loop.time()
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
return (
|
return (
|
||||||
@ -422,7 +424,12 @@ class Ratelimit:
|
|||||||
def is_expired(self) -> bool:
|
def is_expired(self) -> bool:
|
||||||
return self.expires is not None and self._loop.time() > self.expires
|
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:
|
async def acquire(self) -> None:
|
||||||
|
self._last_request = self._loop.time()
|
||||||
if self.is_expired():
|
if self.is_expired():
|
||||||
self.reset()
|
self.reset()
|
||||||
|
|
||||||
@ -532,7 +539,7 @@ class HTTPClient:
|
|||||||
if len(self._buckets) < 256:
|
if len(self._buckets) < 256:
|
||||||
return
|
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:
|
for key in keys:
|
||||||
del self._buckets[key]
|
del self._buckets[key]
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user