aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2022-07-13 10:22:01 -0500
committerJP Dillingham <jp@dillingham.me>2022-07-13 10:22:01 -0500
commitaa2ddbc6c77aab614e1cae1032edd1d625719a8c (patch)
treedbfaa72c3249647ac99929311d8ddcee8226b407 /src
parentfe0e9d3102c27e1b1d4daf585a830f572cd9e799 (diff)
downloadslskd-aa2ddbc6c77aab614e1cae1032edd1d625719a8c.tar.gz
forecast queue position correctly for different queue strategies
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Transfers/Uploads/UploadQueue.cs22
1 files changed, 16 insertions, 6 deletions
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)