aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2025-06-01 14:17:07 -0500
committerGitHub <noreply@github.com>2025-06-01 14:17:07 -0500
commit168926dcc232f59494d9068cb0a8007d47c8db5a (patch)
tree7ea0e6c54838cb71f8a23a3f1947f9388c1382de
parentf9cc90d97274aad7262a26f5b43696f47d821387 (diff)
parentd48d1d351cbb8dcb924af812a81b87b8dd40981d (diff)
downloadslskd-168926dcc232f59494d9068cb0a8007d47c8db5a.tar.gz
Merge pull request #1356 from slskd/fix-transfer-status-queries
Fix remaining transfter State queries using HasFlag()
-rw-r--r--src/slskd/Application.cs12
-rw-r--r--src/slskd/Program.cs2
-rw-r--r--src/slskd/Transfers/API/Controllers/TransfersController.cs7
-rw-r--r--src/slskd/Transfers/Downloads/DownloadService.cs16
-rw-r--r--src/slskd/Transfers/Uploads/UploadService.cs22
5 files changed, 23 insertions, 36 deletions
diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs
index 2449e8e0..e0570ef6 100644
--- a/src/slskd/Application.cs
+++ b/src/slskd/Application.cs
@@ -313,9 +313,7 @@ namespace slskd
// records to be updated if the application has started to shut down so that we can do this cleanup and properly
// disposition them as having failed due to an application shutdown, instead of some random exception thrown while
// things are being disposed.
- var activeUploads = Transfers.Uploads.List(t => t.EndedAt == null || !t.State.HasFlag(TransferStates.Completed), includeRemoved: true)
- .Where(t => t.EndedAt == null || !t.State.HasFlag(TransferStates.Completed)) // https://github.com/slskd/slskd/issues/1280
- .ToList();
+ var activeUploads = Transfers.Uploads.List(t => t.EndedAt == null || !t.State.HasFlag(TransferStates.Completed), includeRemoved: true);
foreach (var upload in activeUploads)
{
@@ -326,9 +324,7 @@ namespace slskd
Transfers.Uploads.Update(upload);
}
- var activeDownloads = Transfers.Downloads.List(t => t.EndedAt == null || !t.State.HasFlag(TransferStates.Completed), includeRemoved: true)
- .Where(t => t.EndedAt == null || !t.State.HasFlag(TransferStates.Completed)) // https://github.com/slskd/slskd/issues/1280
- .ToList();
+ var activeDownloads = Transfers.Downloads.List(t => t.EndedAt == null || !t.State.HasFlag(TransferStates.Completed), includeRemoved: true);
foreach (var download in activeDownloads)
{
@@ -344,9 +340,7 @@ namespace slskd
when the search is complete, so when a search 'dangles' all responses have been lost. to avoid discrepancies,
we need to zero the response and file counts as well as set the state and EndedAt.
*/
- var activeSearches = (await Search.ListAsync(s => s.EndedAt == null || !s.State.HasFlag(SearchStates.Completed)))
- .Where(s => s.EndedAt == null || !s.State.HasFlag(SearchStates.Completed)) // https://github.com/slskd/slskd/issues/1280
- .ToList();
+ var activeSearches = await Search.ListAsync(s => s.EndedAt == null || !s.State.HasFlag(SearchStates.Completed));
foreach (var search in activeSearches)
{
diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs
index 0537824f..dd85bc21 100644
--- a/src/slskd/Program.cs
+++ b/src/slskd/Program.cs
@@ -674,7 +674,7 @@ namespace slskd
if (SQLitePCL.raw.sqlite3_config(SQLitePCL.raw.SQLITE_CONFIG_SERIALIZED) != SQLitePCL.raw.SQLITE_OK)
{
- throw new InvalidOperationException($"SQLite threading mode could not be set to . Please create a GitHub issue to report this and include details about your environment.");
+ throw new InvalidOperationException($"SQLite threading mode could not be set to SERIALIZED ({SQLitePCL.raw.SQLITE_CONFIG_SERIALIZED}). Please create a GitHub issue to report this and include details about your environment.");
}
Log.Debug("SQLite threading mode set to {Mode} ({Number})", "SERIALIZED", SQLitePCL.raw.SQLITE_CONFIG_SERIALIZED);
diff --git a/src/slskd/Transfers/API/Controllers/TransfersController.cs b/src/slskd/Transfers/API/Controllers/TransfersController.cs
index f143e4a7..fdbca1dc 100644
--- a/src/slskd/Transfers/API/Controllers/TransfersController.cs
+++ b/src/slskd/Transfers/API/Controllers/TransfersController.cs
@@ -111,9 +111,7 @@ namespace slskd.Transfers.API
return Forbid();
}
- var transfers = Transfers.Downloads
- .List() // https://github.com/dotnet/efcore/issues/10434
- .Where(t => t.State.HasFlag(Soulseek.TransferStates.Completed));
+ var transfers = Transfers.Downloads.List(t => t.State.HasFlag(Soulseek.TransferStates.Completed));
foreach (var id in transfers.Select(t => t.Id))
{
@@ -182,8 +180,7 @@ namespace slskd.Transfers.API
// get all the transfers that aren't removed
var transfers = Transfers.Uploads
- .List(t => true, includeRemoved: false) // https://github.com/dotnet/efcore/issues/10434
- .Where(t => t.State.HasFlag(Soulseek.TransferStates.Completed));
+ .List(t => t.State.HasFlag(Soulseek.TransferStates.Completed), includeRemoved: false);
foreach (var id in transfers.Select(t => t.Id))
{
diff --git a/src/slskd/Transfers/Downloads/DownloadService.cs b/src/slskd/Transfers/Downloads/DownloadService.cs
index 37df355c..63b04394 100644
--- a/src/slskd/Transfers/Downloads/DownloadService.cs
+++ b/src/slskd/Transfers/Downloads/DownloadService.cs
@@ -87,9 +87,9 @@ namespace slskd.Transfers.Downloads
/// Removes <see cref="TransferStates.Completed"/> downloads older than the specified <paramref name="age"/>.
/// </summary>
/// <param name="age">The age after which downloads are eligible for pruning, in hours.</param>
- /// <param name="state">An optional, additional state by which downloads are filtered for pruning.</param>
+ /// <param name="stateHasFlag">An optional, additional state by which downloads are filtered for pruning.</param>
/// <returns>The number of pruned downloads.</returns>
- int Prune(int age, TransferStates state = TransferStates.Completed);
+ int Prune(int age, TransferStates stateHasFlag = TransferStates.Completed);
/// <summary>
/// Removes the download matching the specified <paramref name="id"/>.
@@ -531,13 +531,13 @@ namespace slskd.Transfers.Downloads
/// Removes <see cref="TransferStates.Completed"/> downloads older than the specified <paramref name="age"/>.
/// </summary>
/// <param name="age">The age after which downloads are eligible for pruning, in hours.</param>
- /// <param name="state">An optional, additional state by which downloads are filtered for pruning.</param>
+ /// <param name="stateHasFlag">An optional, additional state by which downloads are filtered for pruning.</param>
/// <returns>The number of pruned downloads.</returns>
- public int Prune(int age, TransferStates state = TransferStates.Completed)
+ public int Prune(int age, TransferStates stateHasFlag = TransferStates.Completed)
{
- if (!state.HasFlag(TransferStates.Completed))
+ if (!stateHasFlag.HasFlag(TransferStates.Completed))
{
- throw new ArgumentException($"State must include {TransferStates.Completed}", nameof(state));
+ throw new ArgumentException($"State must include {TransferStates.Completed}", nameof(stateHasFlag));
}
try
@@ -550,7 +550,7 @@ namespace slskd.Transfers.Downloads
.Where(t => t.Direction == TransferDirection.Download)
.Where(t => !t.Removed)
.Where(t => t.EndedAt.HasValue && t.EndedAt.Value < cutoffDateTime)
- .Where(t => t.State == state) // https://github.com/dotnet/efcore/issues/20094
+ .Where(t => t.State == stateHasFlag)
.ToList();
foreach (var tx in expired)
@@ -562,7 +562,7 @@ namespace slskd.Transfers.Downloads
if (pruned > 0)
{
- Log.Debug("Pruned {Count} expired downloads with state {State}", pruned, state);
+ Log.Debug("Pruned {Count} expired downloads with state {State}", pruned, stateHasFlag);
}
return pruned;
diff --git a/src/slskd/Transfers/Uploads/UploadService.cs b/src/slskd/Transfers/Uploads/UploadService.cs
index dff1252b..7e96533e 100644
--- a/src/slskd/Transfers/Uploads/UploadService.cs
+++ b/src/slskd/Transfers/Uploads/UploadService.cs
@@ -95,9 +95,9 @@ namespace slskd.Transfers.Uploads
/// Removes <see cref="TransferStates.Completed"/> uploads older than the specified <paramref name="age"/>.
/// </summary>
/// <param name="age">The age after which uploads are eligible for pruning, in minutes.</param>
- /// <param name="state">An optional, additional state by which uploads are filtered for pruning.</param>
+ /// <param name="stateHasFlag">An optional, additional state by which uploads are filtered for pruning.</param>
/// <returns>The number of pruned uploads.</returns>
- int Prune(int age, TransferStates state = TransferStates.Completed);
+ int Prune(int age, TransferStates stateHasFlag = TransferStates.Completed);
/// <summary>
/// Removes the upload matching the specified <paramref name="id"/>.
@@ -489,7 +489,7 @@ namespace slskd.Transfers.Uploads
.AsNoTracking()
.Where(t => t.Direction == TransferDirection.Upload)
.Where(expression)
- .GroupBy(t => true) // https://stackoverflow.com/a/25489456
+ .GroupBy(t => true) // https://stackoverflow.com/a/25489456: The GroupBy(x => true) statement places all items into a single group. The Select statement the allows operations against each group.
.Select(t => new
{
Files = t.Count(),
@@ -541,13 +541,13 @@ namespace slskd.Transfers.Uploads
/// Removes <see cref="TransferStates.Completed"/> uploads older than the specified <paramref name="age"/>.
/// </summary>
/// <param name="age">The age after which uploads are eligible for pruning, in minutes.</param>
- /// <param name="state">An optional, additional state by which uploads are filtered for pruning.</param>
+ /// <param name="stateHasFlag">An optional, additional state by which uploads are filtered for pruning.</param>
/// <returns>The number of pruned uploads.</returns>
- public int Prune(int age, TransferStates state = TransferStates.Completed)
+ public int Prune(int age, TransferStates stateHasFlag = TransferStates.Completed)
{
- if (!state.HasFlag(TransferStates.Completed))
+ if (!stateHasFlag.HasFlag(TransferStates.Completed))
{
- throw new ArgumentException($"State must include {TransferStates.Completed}", nameof(state));
+ throw new ArgumentException($"State must include {TransferStates.Completed}", nameof(stateHasFlag));
}
try
@@ -560,11 +560,7 @@ namespace slskd.Transfers.Uploads
.Where(t => t.Direction == TransferDirection.Upload)
.Where(t => !t.Removed)
.Where(t => t.EndedAt.HasValue && t.EndedAt.Value < cutoffDateTime)
-
- // note: don't try HasFlag() here: https://github.com/dotnet/efcore/issues/20094
- // this won't work because the state is stored as a comma separated string (which we've done deliberately)
- // and EF won't do the necessary work to generate the required SQL
- .Where(t => t.State == state)
+ .Where(t => t.State.HasFlag(stateHasFlag))
.ToList();
foreach (var tx in expired)
@@ -576,7 +572,7 @@ namespace slskd.Transfers.Uploads
if (pruned > 0)
{
- Log.Debug("Pruned {Count} expired uploads with state {State}", pruned, state);
+ Log.Debug("Pruned {Count} expired uploads with state {State}", pruned, stateHasFlag);
}
return pruned;