mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-08 06:47:56 +00:00
Add periodic garbage collection of webhook rate limit cache
This commit is contained in:
parent
93e53be7db
commit
93bf7c6543
2 changed files with 28 additions and 2 deletions
|
|
@ -87,6 +87,23 @@ namespace PluralKit.Bot
|
|||
}
|
||||
}
|
||||
|
||||
public void GarbageCollect()
|
||||
{
|
||||
_logger.Information("Garbage-collecting webhook rate limit buckets...");
|
||||
|
||||
var collected = 0;
|
||||
foreach (var channel in _info.Keys)
|
||||
{
|
||||
if (!_info.TryGetValue(channel, out var info)) continue;
|
||||
|
||||
// Remove all keys that expired more than an hour ago (and of course, haven't been reset)
|
||||
if (info.resetTime < SystemClock.Instance.GetCurrentInstant() - Duration.FromHours(1))
|
||||
if (_info.TryRemove(channel, out _)) collected++;
|
||||
}
|
||||
|
||||
_logger.Information("Garbage-collected {ChannelCount} channels from the webhook rate limit buckets.", collected);
|
||||
}
|
||||
|
||||
private string GetHeader(HttpResponseMessage response, string key)
|
||||
{
|
||||
var firstPair = response.Headers.FirstOrDefault(pair => pair.Key.Equals(key, StringComparison.InvariantCultureIgnoreCase));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue