From eec77d30a76c2ab4809aeb56f635903d81ef6355 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 18 Oct 2026 15:39:56 -0500 Subject: add Query() --- src/slskd/Transfers/Uploads/UploadService.cs | 33 +++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/slskd/Transfers/Uploads/UploadService.cs b/src/slskd/Transfers/Uploads/UploadService.cs index bda47641..a298f523 100644 --- a/src/slskd/Transfers/Uploads/UploadService.cs +++ b/src/slskd/Transfers/Uploads/UploadService.cs @@ -827,21 +827,42 @@ namespace slskd.Transfers.Uploads public List List(Expression> expression, bool includeRemoved) { expression ??= t => true; + /// + /// Returns a list of all uploads matching the specified , projected to type . + /// + /// The Type of the returned projection. + /// The query expression. + /// A value indicating whether to include uploads that have been removed previously. + /// The list of uploads matching the specified query. + public List Query(Func, IQueryable> query, bool includeRemoved = false) + { + ArgumentNullException.ThrowIfNull(query); try { using var context = ContextFactory.CreateDbContext(); - return context.Transfers + var transfers = context.Transfers .AsNoTracking() - .Where(t => t.Direction == TransferDirection.Upload) - .Where(t => !t.Removed || includeRemoved) - .Where(expression) - .ToList(); + .Where(t => t.Direction == TransferDirection.Upload); + + if (!includeRemoved) + { + transfers = transfers.Where(t => !t.Removed); + } + + var result = query(transfers); + + if (result.Provider is not IAsyncQueryProvider) + { + throw new InvalidOperationException("Query must be fully translatable to SQL; in-memory evaluation is not allowed (remove any AsEnumerable() present in the query)"); + } + + return result.ToList(); } catch (Exception ex) { - Log.Error(ex, "Failed to list uploads: {Message}", ex.Message); + Log.Error(ex, "Failed to execute upload queury: {Message}", ex.Message); throw; } } -- cgit v1.2.3