diff options
| author | JP Dillingham <jp@dillingham.me> | 2022-07-13 10:29:12 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-07-13 10:29:12 -0500 |
| commit | 71739c2daf8ed3b0d878b1df7c432d7ff0dc6789 (patch) | |
| tree | dbfaa72c3249647ac99929311d8ddcee8226b407 /src | |
| parent | 9d2ad97f48f773c72a15fbd0e18cff17fa86860e (diff) | |
| parent | aa2ddbc6c77aab614e1cae1032edd1d625719a8c (diff) | |
| download | slskd-71739c2daf8ed3b0d878b1df7c432d7ff0dc6789.tar.gz | |
Merge pull request #545 from slskd/queue
Accurately forecast queue position for both round-robin and FIFO type queues
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Application.cs | 1 | ||||
| -rw-r--r-- | src/slskd/Transfers/Uploads/UploadQueue.cs | 22 |
2 files changed, 17 insertions, 6 deletions
diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index af553475..b0bccd6c 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -846,6 +846,7 @@ namespace slskd if (results.Any()) { + // make sure our average speed (as reported by the server) is reasonably up to date await RefreshUserStatistics(); var forecastedPosition = Transfers.Uploads.Queue.ForecastPosition(username); diff --git a/src/slskd/Transfers/Uploads/UploadQueue.cs b/src/slskd/Transfers/Uploads/UploadQueue.cs index c3b2b3e6..f694a887 100644 --- a/src/slskd/Transfers/Uploads/UploadQueue.cs +++ b/src/slskd/Transfers/Uploads/UploadQueue.cs @@ -310,19 +310,29 @@ namespace slskd.Transfers /// </returns> public int ForecastPosition(string username) { - var group = Users.GetGroup(username); + var groupName = Users.GetGroup(username); // if there's a slot available, the user will enter the queue at position 0 (will start immediately) - if (Groups.TryGetValue(group, out var groupRecord) && groupRecord.SlotAvailable) + if (Groups.TryGetValue(groupName, out var groupRecord) && groupRecord.SlotAvailable) { return 0; } - // no slots are available for this group, so there's at least as many uploads in progress as there are slots. count all - // uploads (in progress or otherwise) - var uploadsForGroup = Uploads.Where(kvp => Users.GetGroup(kvp.Key) == group); + // the Uploads dictionary is keyed by username; gather all of the users that belong to the same group as the requested user + var uploadsForGroup = Uploads.Where(kvp => Users.GetGroup(kvp.Key) == groupName); + + // assuming that the queue will be processed in a true round-robin fashion and that the user will be the last in the + // rotation (worst case), the user's start position will be equal to the number of users downloading or waiting, + 1. + if (groupRecord.Strategy == QueueStrategy.RoundRobin) + { + return uploadsForGroup.Count() + 1; + } - return uploadsForGroup.Count() + 1; + // for FIFO queues, the user will enter the queue at the very back. return the total number of uploads in progress and + // enqueued, + 1. + return uploadsForGroup + .SelectMany(group => group.Value) + .Count() + 1; } private void Configure(Options options) |
