mirror of
https://github.com/Jetsparrow/jetherald.git
synced 2026-01-20 23:56:08 +03:00
Use plan TimeoutMultiplier for ratelimit costs
This commit is contained in:
parent
db970fe87d
commit
51d05b8104
@ -2,14 +2,18 @@
|
||||
|
||||
public class Topic
|
||||
{
|
||||
public uint TopicId { get; set; }
|
||||
public uint TopicId { get; private set; }
|
||||
public uint CreatorId { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Description { get; set; }
|
||||
public string ReadToken { get; set; }
|
||||
public string WriteToken { get; set; }
|
||||
|
||||
public NamespacedId? Sub { get; set; }
|
||||
|
||||
// joined
|
||||
public NamespacedId? Sub { get; private set; }
|
||||
public string? Login { get; private set; }
|
||||
public double TimeoutMultiplier { get; private set; } = 1;
|
||||
|
||||
public override string ToString()
|
||||
=> Name == Description ? Name : $"{Name}: {Description}";
|
||||
|
||||
@ -82,7 +82,7 @@ public class HeartbeatController : ControllerBase
|
||||
if (wasBeating == 0)
|
||||
await Herald.BroadcastMessageRaw(t.TopicId, $"!{t.Description}!:\nHeart \"{heart}\" has started beating at {DateTime.UtcNow:O}");
|
||||
|
||||
Timeouts.ApplyCost(t.TopicId, Config.HeartbeatCost);
|
||||
Timeouts.ApplyCost(t.TopicId, Config.HeartbeatCost * t.TimeoutMultiplier);
|
||||
|
||||
return new OkResult();
|
||||
}
|
||||
|
||||
@ -68,7 +68,7 @@ public class ReportController : ControllerBase
|
||||
|
||||
await Herald.BroadcastMessageRaw(t.TopicId, $"|{t.Description}|:\n{args.Message}");
|
||||
|
||||
Timeouts.ApplyCost(t.TopicId, Config.ReportCost);
|
||||
Timeouts.ApplyCost(t.TopicId, Config.ReportCost * t.TimeoutMultiplier);
|
||||
|
||||
return new OkResult();
|
||||
}
|
||||
|
||||
@ -101,7 +101,11 @@ public class DbContext : IDisposable
|
||||
|
||||
public Task<Topic> GetTopic(string name)
|
||||
=> Tran.QuerySingleOrDefaultAsync<Topic>(
|
||||
"SELECT * FROM topic WHERE Name = @name",
|
||||
@"SELECT t.*, u.Login, p.TimeoutMultiplier
|
||||
FROM `topic` t
|
||||
JOIN `user` u ON t.CreatorId = u.UserId
|
||||
JOIN `plan` p ON u.PlanId = p.PlanId
|
||||
WHERE t.Name = @name;",
|
||||
new { name });
|
||||
|
||||
public Task<int> DeleteTopic(string name, uint userId)
|
||||
|
||||
@ -21,8 +21,9 @@ public class LeakyBucket
|
||||
return time > debtLimit;
|
||||
}
|
||||
|
||||
public void ApplyCost(uint key, int cost)
|
||||
public void ApplyCost(uint key, double cost)
|
||||
{
|
||||
if (cost <= 0) return;
|
||||
expiryDates.AddOrUpdate(key,
|
||||
key => DateTime.UtcNow.AddSeconds(cost),
|
||||
(key, oldDebt) =>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user