aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2026-10-04 16:34:40 -0500
committerJP Dillingham <jp@dillingham.me>2026-10-04 16:34:40 -0500
commit05d82deee08aa1788ce1d0910648cf6f942a7ba3 (patch)
tree97c564ffb488d7afa9bc950289eed582f294e32c /src
parent1ad32bdda6f0dd234b3675ae525e77200a1be29a (diff)
downloadslskd-05d82deee08aa1788ce1d0910648cf6f942a7ba3.tar.gz
consider GlobalSlots when forecasting
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Transfers/Uploads/UploadQueue.cs30
1 files changed, 20 insertions, 10 deletions
diff --git a/src/slskd/Transfers/Uploads/UploadQueue.cs b/src/slskd/Transfers/Uploads/UploadQueue.cs
index 9fc48497..42d70194 100644
--- a/src/slskd/Transfers/Uploads/UploadQueue.cs
+++ b/src/slskd/Transfers/Uploads/UploadQueue.cs
@@ -99,6 +99,11 @@ namespace slskd.Transfers.Uploads
/// Computes the estimated queue position of the specified <paramref name="username"/> if they were to enqueue a file,
/// or zero if the transfer could start immediately.
/// </summary>
+ /// <remarks>
+ /// The returned position is relative to the user's group only. Higher priority groups are not factored in
+ /// because of the amount of data that would need to be processed to compute a number, and how variable it
+ /// would be due to the interplay of slot availability, number of higher priority users waiting, etc.
+ /// </remarks>
/// <param name="username">The username for which to estimate.</param>
/// <returns>
/// The estimated queue position if the user were to enqueue a file, or zero if the transfer could start immediately.
@@ -387,6 +392,11 @@ namespace slskd.Transfers.Uploads
/// Computes the estimated queue position of the specified <paramref name="username"/> if they were to enqueue a file,
/// or zero if the transfer could start immediately.
/// </summary>
+ /// <remarks>
+ /// The returned position is relative to the user's group only. Higher priority groups are not factored in
+ /// because of the amount of data that would need to be processed to compute a number, and how variable it
+ /// would be due to the interplay of slot availability, number of higher priority users waiting, etc.
+ /// </remarks>
/// <param name="username">The username for which to estimate.</param>
/// <returns>
/// The estimated queue position if the user were to enqueue a file, or zero if the transfer could start immediately.
@@ -395,24 +405,24 @@ namespace slskd.Transfers.Uploads
{
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(groupName, out var groupRecord) && groupRecord.HasAvailableSlot)
+ if (!Groups.TryGetValue(groupName, out var groupRecord))
{
- return (string.Empty, 0, 0, 0);
+ throw new SlskdException($"Upload group {groupName} doesn't have an entry in upload dictionary. Please report this on GitHub: {Program.IssuesUrl}");
}
- var totalSlots = groupRecord.Slots;
- var freeSlots = totalSlots - groupRecord.UsedSlots.Count;
+ var totalSlots = Math.Min(GlobalSlots, groupRecord.Slots);
+ var freeSlots = Math.Max(0, totalSlots - groupRecord.UsedSlots.Count);
+
+ // if there's a slot available, the user will enter the queue at position 0 (will start immediately)
+ if (freeSlots > 0)
+ {
+ return (groupName, totalSlots, freeSlots, 0);
+ }
// the Uploads dictionary is keyed by username; gather all of the users that belong to the same group as the requested user
// a user's group can change either by user changing the config or updating counts (for leech detection); resist the urge to cache this
var uploadsForGroup = UploadDictionary.Where(kvp => Users.GetGroup(kvp.Key) == groupName);
- if (groupRecord is null)
- {
- throw new SlskdException($"Upload group {groupName} doesn't have an entry in upload dictionary. Please report this on GitHub: {Program.IssuesUrl}");
- }
-
// 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)