aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Transfers/Uploads
diff options
context:
space:
mode:
Diffstat (limited to 'src/slskd/Transfers/Uploads')
-rw-r--r--src/slskd/Transfers/Uploads/UploadService.cs54
1 files changed, 2 insertions, 52 deletions
diff --git a/src/slskd/Transfers/Uploads/UploadService.cs b/src/slskd/Transfers/Uploads/UploadService.cs
index 72e3c0ef..9bb09f66 100644
--- a/src/slskd/Transfers/Uploads/UploadService.cs
+++ b/src/slskd/Transfers/Uploads/UploadService.cs
@@ -101,16 +101,6 @@ namespace slskd.Transfers.Uploads
Transfer Find(Expression<Func<Transfer, bool>> expression);
/// <summary>
- /// Returns a summary of the uploads matching the specified <paramref name="expression"/>. This can be expensive;
- /// consider caching.
- /// </summary>
- /// <param name="expression">The expression used to select uploads for summarization.</param>
- /// <returns>
- /// The generated summary, including the number of files and total size in bytes.
- /// </returns>
- (int Files, long Bytes) Summarize(Expression<Func<Transfer, bool>> expression);
-
- /// <summary>
/// Gets upload statistics for the specified <paramref name="username"/>.
/// </summary>
/// <param name="username">The username of the user.</param>
@@ -632,7 +622,6 @@ namespace slskd.Transfers.Uploads
Direction = TransferDirection.Upload,
Filename = filename, // important! use the remote filename
Size = localFileLength,
- StartOffset = 0, // potentially updated later during handshaking
RequestedAt = DateTime.UtcNow,
State = TransferStates.Queued | TransferStates.Locally,
};
@@ -731,51 +720,12 @@ namespace slskd.Transfers.Uploads
return context.Transfers
.AsNoTracking()
.Where(t => t.Direction == TransferDirection.Upload)
- .Where(expression).FirstOrDefault();
- }
- catch (Exception ex)
- {
- Log.Error(ex, "Failed to find upload: {Message}", ex.Message);
- throw;
- }
- }
-
- /// <summary>
- /// Returns a summary of the uploads matching the specified <paramref name="expression"/>. This can be expensive;
- /// consider caching.
- /// </summary>
- /// <param name="expression">The expression used to select uploads for summarization.</param>
- /// <returns>
- /// The generated summary, including the number of files and total size in bytes.
- /// </returns>
- public (int Files, long Bytes) Summarize(Expression<Func<Transfer, bool>> expression)
- {
- expression ??= t => true;
-
- try
- {
- using var context = ContextFactory.CreateDbContext();
-
- var query = context.Transfers
- .AsNoTracking()
- .Where(t => t.Direction == TransferDirection.Upload)
.Where(expression)
- .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(),
- Bytes = t.Sum(x => x.Size),
- });
-
- Log.Verbose("{Method} SQL: {@Query}", nameof(Summarize), query.ToQueryString());
-
- var stats = query.FirstOrDefault();
-
- return (stats?.Files ?? 0, stats?.Bytes ?? 0);
+ .SingleOrDefault();
}
catch (Exception ex)
{
- Log.Error(ex, "Failed to list uploads: {Message}", ex.Message);
+ Log.Error(ex, "Failed to find upload: {Message}", ex.Message);
throw;
}
}