aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2026-04-26 23:12:51 -0500
committerJP Dillingham <jp@dillingham.me>2026-04-26 23:12:51 -0500
commit9507e547dd68f1142b0b7a455a52ce5b6ad3d50e (patch)
treec236adab2671f26e8c946a3ccf3a821dd9883528 /src
parent59e2e9de29de2dea134c5fbaf3a518b2fe0d82b2 (diff)
downloadslskd-9507e547dd68f1142b0b7a455a52ce5b6ad3d50e.tar.gz
tweak Batch more
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Transfers/Types/Batch.cs43
1 files changed, 22 insertions, 21 deletions
diff --git a/src/slskd/Transfers/Types/Batch.cs b/src/slskd/Transfers/Types/Batch.cs
index 30633cc9..aa61f069 100644
--- a/src/slskd/Transfers/Types/Batch.cs
+++ b/src/slskd/Transfers/Types/Batch.cs
@@ -37,6 +37,7 @@ using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
+using System.Text.Json.Serialization;
using Soulseek;
public class Batch
@@ -47,41 +48,41 @@ public class Batch
public Guid Id { get; init; }
public string Username { get; init; }
public TransferDirection Direction { get; } = TransferDirection.Download;
+ public string Destination { get; init; }
+ public int Files { get; init; }
+ public long Size { get; init; }
[NotMapped]
public TransferStates State => ComputeState();
public DateTime CreatedAt { get; init; } = DateTime.UtcNow;
+ public DateTime? EndedAt { get; set; } // todo: set when the last file is completed, for performance reasons
- [NotMapped]
- public DateTime? EndedAt => Transfers.Max(t => t.EndedAt);
-
- public ICollection<Transfer> Transfers { get; set; } = [];
+ /// <summary>
+ /// The transfers associated with the batch.
+ /// </summary>
+ /// <remarks>
+ /// Lazy loaded. If not loaded with the batch record, the collection and all of the statistics will be null.
+ /// </remarks>
+ public ICollection<Transfer> Transfers { get; set; }
- public string Destination { get; init; }
-
- [NotMapped]
- public long BytesTransferred => Transfers.Sum(t => t.BytesTransferred);
[NotMapped]
- public int Files => Transfers.Count;
- [NotMapped]
- public long Size => Transfers.Sum(t => t.Size);
- [NotMapped]
- public long BytesRemaining => Size - BytesTransferred;
+ public long BytesTransferred { get; set; }
+
[NotMapped]
- public TimeSpan ElapsedTime => DateTime.UtcNow - CreatedAt;
+ public long BytesRemaining { get; set; }
+
[NotMapped]
- public double PercentComplete => Size == 0 ? 0 : (BytesTransferred / (double)Size) * 100;
+ public TimeSpan ElapsedTime => (EndedAt ?? DateTime.UtcNow) - CreatedAt;
[NotMapped]
- public double AverageSpeed => Transfers
- .Where(t => TransferStateCategories.Successful.Contains(t.State))
- .Select(t => t.AverageSpeed)
- .DefaultIfEmpty(0)
- .Average();
+ public double PercentComplete { get; set; }
[NotMapped]
- public bool Removed => Transfers.All(t => t.Removed);
+ public double AverageSpeed { get; set; }
+
+ [JsonIgnore]
+ public bool Removed { get; set; }
private TransferStates ComputeState()
{