From b88da4223defea838dee153a0dc464773e31e737 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Thu, 25 Dec 2025 18:46:25 -0600 Subject: add TransferStateCategories --- .../Transfers/Types/TransferStateCategories.cs | 91 ++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 src/slskd/Transfers/Types/TransferStateCategories.cs (limited to 'src') diff --git a/src/slskd/Transfers/Types/TransferStateCategories.cs b/src/slskd/Transfers/Types/TransferStateCategories.cs new file mode 100644 index 00000000..71f8e962 --- /dev/null +++ b/src/slskd/Transfers/Types/TransferStateCategories.cs @@ -0,0 +1,91 @@ +// +// Copyright (c) slskd Team. All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see https://www.gnu.org/licenses/. +// + +namespace slskd.Transfers; + +using System.Collections.Generic; +using Soulseek; + +/// +/// A collection of transfer state integers, collected into arrays that represent common states. +/// +/// +/// SQLite can't take advantage of indexes when using bitwise operations, which is what Entity Franework +/// turns HasFlag() expressions into. These arrays allow us to use IN expressions instead of bitwise. +/// +public static class TransferStateCategories +{ + /// + /// All states representing a successful transfer: + /// + /// + /// + /// + /// + public static readonly HashSet Successful = [(int)(TransferStates.Completed | TransferStates.Succeeded)]; + + /// + /// All states representing a failed transfer: + /// + /// + /// + /// + /// + /// + /// + /// + /// + public static readonly HashSet Failed = [ + (int)(TransferStates.Completed | TransferStates.Cancelled), + (int)(TransferStates.Completed | TransferStates.TimedOut), + (int)(TransferStates.Completed | TransferStates.Errored), + (int)(TransferStates.Completed | TransferStates.Rejected), + (int)(TransferStates.Completed | TransferStates.Aborted), + ]; + + /// + /// All states containing the flag. + /// + public static readonly HashSet Completed = [.. Successful, .. Failed]; + + /// + /// All states representing a queued transfer: + /// + /// + /// + /// + /// + /// + public static readonly HashSet Queued = [ + (int)TransferStates.Queued, + (int)(TransferStates.Queued | TransferStates.Locally), + (int)(TransferStates.Queued | TransferStates.Remotely), + ]; + + /// + /// All states representing a transfer that is in progress: + /// + /// + /// + /// + /// + /// + public static readonly HashSet InProgress = [ + (int)TransferStates.Initializing, + (int)TransferStates.InProgress, + ]; +} \ No newline at end of file -- cgit v1.2.3