From 9964d73a431a869175f88468496ac58b97fc246f Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Mon, 26 May 2025 17:49:46 -0500 Subject: eliminate HasFlag workaround --- src/slskd/Application.cs | 12 +++--------- .../Transfers/API/Controllers/TransfersController.cs | 7 ++----- src/slskd/Transfers/Downloads/DownloadService.cs | 16 ++++++++-------- src/slskd/Transfers/Uploads/UploadService.cs | 20 ++++++++------------ 4 files changed, 21 insertions(+), 34 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/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 downloads older than the specified . /// /// The age after which downloads are eligible for pruning, in hours. - /// An optional, additional state by which downloads are filtered for pruning. + /// An optional, additional state by which downloads are filtered for pruning. /// The number of pruned downloads. - int Prune(int age, TransferStates state = TransferStates.Completed); + int Prune(int age, TransferStates stateHasFlag = TransferStates.Completed); /// /// Removes the download matching the specified . @@ -531,13 +531,13 @@ namespace slskd.Transfers.Downloads /// Removes downloads older than the specified . /// /// The age after which downloads are eligible for pruning, in hours. - /// An optional, additional state by which downloads are filtered for pruning. + /// An optional, additional state by which downloads are filtered for pruning. /// The number of pruned downloads. - 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..1dcd7406 100644 --- a/src/slskd/Transfers/Uploads/UploadService.cs +++ b/src/slskd/Transfers/Uploads/UploadService.cs @@ -95,9 +95,9 @@ namespace slskd.Transfers.Uploads /// Removes uploads older than the specified . /// /// The age after which uploads are eligible for pruning, in minutes. - /// An optional, additional state by which uploads are filtered for pruning. + /// An optional, additional state by which uploads are filtered for pruning. /// The number of pruned uploads. - int Prune(int age, TransferStates state = TransferStates.Completed); + int Prune(int age, TransferStates stateHasFlag = TransferStates.Completed); /// /// Removes the upload matching the specified . @@ -541,13 +541,13 @@ namespace slskd.Transfers.Uploads /// Removes uploads older than the specified . /// /// The age after which uploads are eligible for pruning, in minutes. - /// An optional, additional state by which uploads are filtered for pruning. + /// An optional, additional state by which uploads are filtered for pruning. /// The number of pruned uploads. - 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; -- cgit v1.2.3 From d57d8a065bc384442199a91a7a388dc14b733f9e Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Mon, 26 May 2025 17:50:08 -0500 Subject: update typo'ed error message --- src/slskd/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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); -- cgit v1.2.3 From 068542fc0d07840eb49dc5f70c578ae31ace1048 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Mon, 26 May 2025 17:50:18 -0500 Subject: add context to note --- src/slskd/Transfers/Uploads/UploadService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/slskd/Transfers/Uploads/UploadService.cs b/src/slskd/Transfers/Uploads/UploadService.cs index 1dcd7406..7e96533e 100644 --- a/src/slskd/Transfers/Uploads/UploadService.cs +++ b/src/slskd/Transfers/Uploads/UploadService.cs @@ -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(), -- cgit v1.2.3 From 7d2a8ae7caedefd239fd15c273fc763d081bb15c Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 1 Jun 2025 12:09:02 -0500 Subject: pin sdk version to 9.0.203; 9.0.300 breaks colored console output under dotnet watch --- .github/workflows/ci.yml | 2 +- global.json | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 global.json diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5a6072c0..96fa1690 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,7 +8,7 @@ on: workflow_dispatch: env: - DOTNET_VERSION: '8' + DOTNET_VERSION: '9.0.203' jobs: build: diff --git a/global.json b/global.json new file mode 100644 index 00000000..a1c2da40 --- /dev/null +++ b/global.json @@ -0,0 +1,6 @@ +{ + "sdk": { + "version": "9.0.203", // until colored console output using 'dotnet watch' is fixed + "rollForward": "disable" + } +} \ No newline at end of file -- cgit v1.2.3 From d48d1d351cbb8dcb924af812a81b87b8dd40981d Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 1 Jun 2025 13:58:50 -0500 Subject: revert pinning of sdk --- .github/workflows/ci.yml | 2 +- global.json | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) delete mode 100644 global.json diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 96fa1690..5a6072c0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,7 +8,7 @@ on: workflow_dispatch: env: - DOTNET_VERSION: '9.0.203' + DOTNET_VERSION: '8' jobs: build: diff --git a/global.json b/global.json deleted file mode 100644 index a1c2da40..00000000 --- a/global.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "sdk": { - "version": "9.0.203", // until colored console output using 'dotnet watch' is fixed - "rollForward": "disable" - } -} \ No newline at end of file -- cgit v1.2.3