mirror of
https://github.com/Jetsparrow/jetherald.git
synced 2026-01-21 07:56:09 +03:00
LeakyBucket DateTime fixes
- Remove use of local DateTime.Now - Always take UtcNow only once at method entry
This commit is contained in:
parent
c8f505ba03
commit
415979c61e
@ -17,8 +17,9 @@ namespace JetHerald
|
|||||||
|
|
||||||
public bool IsTimedOut(uint key)
|
public bool IsTimedOut(uint key)
|
||||||
{
|
{
|
||||||
var debtLimit = DateTime.Now.AddSeconds(config.DebtLimitSeconds);
|
var now = DateTime.UtcNow;
|
||||||
var time = expiryDates.GetValueOrDefault(key, DateTime.Now);
|
var debtLimit = now.AddSeconds(config.DebtLimitSeconds);
|
||||||
|
var time = expiryDates.GetValueOrDefault(key, now);
|
||||||
Console.WriteLine(time);
|
Console.WriteLine(time);
|
||||||
return time > debtLimit;
|
return time > debtLimit;
|
||||||
}
|
}
|
||||||
@ -26,11 +27,12 @@ namespace JetHerald
|
|||||||
public void ApplyCost(uint key, int cost)
|
public void ApplyCost(uint key, int cost)
|
||||||
{
|
{
|
||||||
expiryDates.AddOrUpdate(key,
|
expiryDates.AddOrUpdate(key,
|
||||||
key => DateTime.Now.AddSeconds(cost),
|
key => DateTime.UtcNow.AddSeconds(cost),
|
||||||
(key, oldDebt) =>
|
(key, oldDebt) =>
|
||||||
{
|
{
|
||||||
if (oldDebt < DateTime.Now)
|
var now = DateTime.UtcNow;
|
||||||
return DateTime.Now.AddSeconds(cost);
|
if (oldDebt < now)
|
||||||
|
return now.AddSeconds(cost);
|
||||||
|
|
||||||
return oldDebt.AddSeconds(cost);
|
return oldDebt.AddSeconds(cost);
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user