aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2024-01-17 08:29:35 -0600
committerJP Dillingham <jp@dillingham.me>2024-01-17 08:29:35 -0600
commit899d62a990db36492fc1ed7537faea578ef509a6 (patch)
tree8d7db8dcca13dff60808172c9d8986f90300a2ae /src
parentd4edf6432ae7b4e8c46f0861a155e464f152b4c9 (diff)
downloadslskd-899d62a990db36492fc1ed7537faea578ef509a6.tar.gz
implement weekly
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Application.cs43
1 files changed, 23 insertions, 20 deletions
diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs
index a85cbff7..4bbd03c7 100644
--- a/src/slskd/Application.cs
+++ b/src/slskd/Application.cs
@@ -484,6 +484,7 @@ namespace slskd
}
// in order to properly determine if the requested file would exceed any limits, we need to know the size of the file
+ // it helps, too, that this will tell us whether the file is even shared.
(string Host, string Filename, long Size) resolved;
try
@@ -609,26 +610,28 @@ namespace slskd
}
}
- //cutoffDateTime = DateTime.UtcNow.AddDays(-1);
- //var daily = Transfers.Uploads.Hypothesize(
- // expression: t =>
- // t.Username == username
- // && t.StartedAt >= cutoffDateTime
- // && !t.State.HasFlag(erroredState)
- // && t.Exception == null,
- // hypothetical: new Transfers.Transfer()
- // {
- // Filename = resolved.Filename,
- // Size = resolved.Size,
- // });
-
- //Log.Debug("Fetched daily stats: {Stats} ({Time}ms)", weekly, sw.ElapsedMilliseconds);
-
- //if (OverLimits(daily, limits.Daily, out var dailyReason))
- //{
- // Log.Information("Rejected enqueue request for user {Username}: Daily {Reason}", dailyReason);
- // throw new DownloadEnqueueException($"Daily {dailyReason}");
- //}
+ // lastly, check daily limits. the criteria for this is the same as weekly, just looking over the previous day instead
+ // of the previous 7.
+ if (!IsNull(limits.Daily))
+ {
+ var erroredState = TransferStates.Completed | TransferStates.Errored;
+ var cutoffDateTime = DateTime.UtcNow.AddDays(-1);
+ var daily = Transfers.Uploads.Summarize(
+ expression: t =>
+ t.Username == username
+ && t.StartedAt >= cutoffDateTime
+ && t.EndedAt != null
+ && !t.State.HasFlag(erroredState)
+ && t.Exception == null);
+
+ Log.Debug("Fetched daily stats: files: {Files}, bytes: {Bytes} ({Time}ms)", daily.Files, daily.Bytes, sw.ElapsedMilliseconds);
+
+ if (OverLimits(daily, limits!.Daily, resolved.Size, out var dailyReason))
+ {
+ Log.Information("Rejected enqueue request for user {Username}: Daily {Reason}", username, dailyReason);
+ throw new DownloadEnqueueException($"Daily {dailyReason}");
+ }
+ }
sw.Stop();
Log.Debug("Enqueue decision made in {Duration}ms", sw.ElapsedMilliseconds);