diff options
| author | JP Dillingham <jp@dillingham.me> | 2024-01-17 08:28:44 -0600 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2024-01-17 08:28:44 -0600 |
| commit | d4edf6432ae7b4e8c46f0861a155e464f152b4c9 (patch) | |
| tree | 16ff0d1fc37a2cc74082193e77f1887fb5e8a093 /src | |
| parent | eb552e0d8118642f08289c239f02b08bd0bed735 (diff) | |
| download | slskd-d4edf6432ae7b4e8c46f0861a155e464f152b4c9.tar.gz | |
implement weekly limits
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Application.cs | 45 |
1 files changed, 23 insertions, 22 deletions
diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index a065470d..a85cbff7 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -585,28 +585,29 @@ namespace slskd } } - //// start with weekly, as this is the most likely limit to be hit and we want to keep the work to a minimum - //var erroredState = TransferStates.Completed | TransferStates.Errored; - //var cutoffDateTime = DateTime.UtcNow.AddDays(-7); - //var weekly = 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 weekly stats: {Stats} ({Time}ms)", weekly, sw.ElapsedMilliseconds); - - //if (OverLimits(weekly, limits.Weekly, out var weeklyReason)) - //{ - // Log.Information("Rejected enqueue request for user {Username}: Weekly {Reason}", weeklyReason); - // throw new DownloadEnqueueException($"Weekly {weeklyReason}"); - //} + // start with weekly, as this is the most likely limit to be hit and we want to keep the work to a minimum + // transfers that 'count' for the weekly limit are uploads that started within the last week, which have ended, + // that were not errored + if (!IsNull(limits.Weekly)) + { + var erroredState = TransferStates.Completed | TransferStates.Errored; + var cutoffDateTime = DateTime.UtcNow.AddDays(-7); + var weekly = Transfers.Uploads.Summarize( + expression: t => + t.Username == username + && t.StartedAt >= cutoffDateTime + && t.EndedAt != null + && !t.State.HasFlag(erroredState) + && t.Exception == null); + + Log.Debug("Fetched weekly stats: files: {Files}, bytes: {Bytes} ({Time}ms)", weekly.Files, weekly.Bytes, sw.ElapsedMilliseconds); + + if (OverLimits(weekly, limits!.Weekly, resolved.Size, out var weeklyReason)) + { + Log.Information("Rejected enqueue request for user {Username}: Weekly {Reason}", username, weeklyReason); + throw new DownloadEnqueueException($"Weekly {weeklyReason}"); + } + } //cutoffDateTime = DateTime.UtcNow.AddDays(-1); //var daily = Transfers.Uploads.Hypothesize( |
