This commit is contained in:
Roger Far 2026-02-11 20:22:28 -07:00
parent e51e5cde45
commit 580c7132c6
6 changed files with 156 additions and 149 deletions

View file

@ -17,10 +17,10 @@ public class TorrentData(DataContext dataContext) : ITorrentData
try try
{ {
_torrentCache ??= await dataContext.Torrents _torrentCache ??= await dataContext.Torrents
.AsNoTracking() .AsNoTracking()
.AsSplitQuery() .AsSplitQuery()
.Include(m => m.Downloads) .Include(m => m.Downloads)
.ToListAsync(); .ToListAsync();
return [.. _torrentCache.OrderBy(m => m.Priority ?? 9999).ThenBy(m => m.Added)]; return [.. _torrentCache.OrderBy(m => m.Priority ?? 9999).ThenBy(m => m.Added)];
} }

View file

@ -1,5 +1,4 @@
using RdtClient.Data.Enums; using RdtClient.Data.Enums;
using RdtClient.Data.Models.Data;
using RdtClient.Data.Models.TorrentClient; using RdtClient.Data.Models.TorrentClient;
namespace RdtClient.Data.Models.Internal; namespace RdtClient.Data.Models.Internal;

View file

@ -22,7 +22,7 @@ public class WebsocketsUpdater(ILogger<WebsocketsUpdater> logger, IServiceProvid
{ {
using var scope = serviceProvider.CreateScope(); using var scope = serviceProvider.CreateScope();
var remoteService = scope.ServiceProvider.GetRequiredService<RemoteService>(); var remoteService = scope.ServiceProvider.GetRequiredService<RemoteService>();
await remoteService.Update(); await remoteService.Update();
} }
catch (Exception ex) catch (Exception ex)
@ -30,10 +30,10 @@ public class WebsocketsUpdater(ILogger<WebsocketsUpdater> logger, IServiceProvid
logger.LogError(ex, $"Unexpected error occurred in WebsocketsUpdater: {ex.Message}"); logger.LogError(ex, $"Unexpected error occurred in WebsocketsUpdater: {ex.Message}");
} }
var delay = RdtHub.HasConnections var delay = RdtHub.HasConnections
? TimeSpan.FromSeconds(1) ? TimeSpan.FromSeconds(1)
: TimeSpan.FromSeconds(5); : TimeSpan.FromSeconds(5);
await Task.Delay(delay, stoppingToken); await Task.Delay(delay, stoppingToken);
} }

View file

@ -221,23 +221,26 @@ public class QBittorrent(ILogger<QBittorrent> logger, Settings settings, Authent
var rdProgress = Math.Clamp(torrent.RdProgress ?? 0.0, 0.0, 100.0) / 100.0; var rdProgress = Math.Clamp(torrent.RdProgress ?? 0.0, 0.0, 100.0) / 100.0;
var bytesTotal = torrent.RdSize ?? 0; var bytesTotal = torrent.RdSize ?? 0;
var speed = torrent.RdSpeed ?? 0; var speed = torrent.RdSpeed ?? 0;
var bytesDone = (Int64) (bytesTotal * rdProgress); var bytesDone = (Int64)(bytesTotal * rdProgress);
Double downloadProgress = 0; Double downloadProgress = 0;
if (torrent.Downloads is { Count: > 0 }) if (torrent.Downloads is { Count: > 0 })
{ {
var dlBytesDone = torrent.Downloads.Sum(m => m.BytesDone); var dlBytesDone = torrent.Downloads.Sum(m => m.BytesDone);
var dlBytesTotal = torrent.Downloads.Sum(m => m.BytesTotal); var dlBytesTotal = torrent.Downloads.Sum(m => m.BytesTotal);
speed = (Int32) torrent.Downloads.Average(m => m.Speed); speed = (Int32)torrent.Downloads.Average(m => m.Speed);
downloadProgress = bytesTotal > 0 ? Math.Clamp((Double) dlBytesDone / dlBytesTotal, 0.0, 1.0) : 0; downloadProgress = bytesTotal > 0 ? Math.Clamp((Double)dlBytesDone / dlBytesTotal, 0.0, 1.0) : 0;
} }
var progress = (rdProgress + downloadProgress) / 2.0; var progress = (rdProgress + downloadProgress) / 2.0;
var remaining = TimeSpan.Zero; var remaining = TimeSpan.Zero;
var bytesRemaining = bytesTotal - bytesDone; var bytesRemaining = bytesTotal - bytesDone;
if (speed > 0 && bytesRemaining > 0) if (speed > 0 && bytesRemaining > 0)
{ {
remaining = TimeSpan.FromSeconds(bytesRemaining / (Double)speed); remaining = TimeSpan.FromSeconds(bytesRemaining / (Double)speed);
// In case there is clock skew // In case there is clock skew
if (remaining < TimeSpan.Zero) if (remaining < TimeSpan.Zero)
{ {

View file

@ -10,65 +10,67 @@ public class RemoteService(IHubContext<RdtHub> hub, Torrents torrents)
var allTorrents = await torrents.Get(); var allTorrents = await torrents.Get();
var torrentDtos = allTorrents.Select(torrent => new TorrentDto var torrentDtos = allTorrents.Select(torrent => new TorrentDto
{ {
TorrentId = torrent.TorrentId, TorrentId = torrent.TorrentId,
Hash = torrent.Hash, Hash = torrent.Hash,
Category = torrent.Category, Category = torrent.Category,
DownloadAction = torrent.DownloadAction, DownloadAction = torrent.DownloadAction,
FinishedAction = torrent.FinishedAction, FinishedAction = torrent.FinishedAction,
FinishedActionDelay = torrent.FinishedActionDelay, FinishedActionDelay = torrent.FinishedActionDelay,
HostDownloadAction = torrent.HostDownloadAction, HostDownloadAction = torrent.HostDownloadAction,
DownloadMinSize = torrent.DownloadMinSize, DownloadMinSize = torrent.DownloadMinSize,
IncludeRegex = torrent.IncludeRegex, IncludeRegex = torrent.IncludeRegex,
ExcludeRegex = torrent.ExcludeRegex, ExcludeRegex = torrent.ExcludeRegex,
DownloadManualFiles = torrent.DownloadManualFiles, DownloadManualFiles = torrent.DownloadManualFiles,
DownloadClient = torrent.DownloadClient, DownloadClient = torrent.DownloadClient,
Added = torrent.Added, Added = torrent.Added,
FilesSelected = torrent.FilesSelected, FilesSelected = torrent.FilesSelected,
Completed = torrent.Completed, Completed = torrent.Completed,
IsFile = torrent.IsFile, IsFile = torrent.IsFile,
Priority = torrent.Priority, Priority = torrent.Priority,
RetryCount = torrent.RetryCount, RetryCount = torrent.RetryCount,
DownloadRetryAttempts = torrent.DownloadRetryAttempts, DownloadRetryAttempts = torrent.DownloadRetryAttempts,
TorrentRetryAttempts = torrent.TorrentRetryAttempts, TorrentRetryAttempts = torrent.TorrentRetryAttempts,
DeleteOnError = torrent.DeleteOnError, DeleteOnError = torrent.DeleteOnError,
Lifetime = torrent.Lifetime, Lifetime = torrent.Lifetime,
Error = torrent.Error, Error = torrent.Error,
RdId = torrent.RdId, RdId = torrent.RdId,
RdName = torrent.RdName, RdName = torrent.RdName,
RdSize = torrent.RdSize, RdSize = torrent.RdSize,
RdHost = torrent.RdHost, RdHost = torrent.RdHost,
RdSplit = torrent.RdSplit, RdSplit = torrent.RdSplit,
RdProgress = torrent.RdProgress, RdProgress = torrent.RdProgress,
RdStatus = torrent.RdStatus, RdStatus = torrent.RdStatus,
RdStatusRaw = torrent.RdStatusRaw, RdStatusRaw = torrent.RdStatusRaw,
RdAdded = torrent.RdAdded, RdAdded = torrent.RdAdded,
RdEnded = torrent.RdEnded, RdEnded = torrent.RdEnded,
RdSpeed = torrent.RdSpeed, RdSpeed = torrent.RdSpeed,
RdSeeders = torrent.RdSeeders, RdSeeders = torrent.RdSeeders,
Files = torrent.Files, Files = torrent.Files,
Downloads = torrent.Downloads.Select(download => new DownloadDto Downloads = torrent.Downloads.Select(download => new DownloadDto
{ {
DownloadId = download.DownloadId, DownloadId = download.DownloadId,
TorrentId = download.TorrentId, TorrentId = download.TorrentId,
Path = download.Path, Path = download.Path,
Link = download.Link, Link = download.Link,
Added = download.Added, Added = download.Added,
DownloadQueued = download.DownloadQueued, DownloadQueued = download.DownloadQueued,
DownloadStarted = download.DownloadStarted, DownloadStarted = download.DownloadStarted,
DownloadFinished = download.DownloadFinished, DownloadFinished = download.DownloadFinished,
UnpackingQueued = download.UnpackingQueued, UnpackingQueued = download.UnpackingQueued,
UnpackingStarted = download.UnpackingStarted, UnpackingStarted = download.UnpackingStarted,
UnpackingFinished = download.UnpackingFinished, UnpackingFinished = download.UnpackingFinished,
Completed = download.Completed, Completed = download.Completed,
RetryCount = download.RetryCount, RetryCount = download.RetryCount,
Error = download.Error, Error = download.Error,
BytesTotal = download.BytesTotal, BytesTotal = download.BytesTotal,
BytesDone = download.BytesDone, BytesDone = download.BytesDone,
Speed = download.Speed Speed = download.Speed
}).ToList() })
}).ToList(); .ToList()
})
.ToList();
await hub.Clients.All.SendCoreAsync("update", await hub.Clients.All.SendCoreAsync("update",
[ [
torrentDtos torrentDtos

View file

@ -22,64 +22,66 @@ public class TorrentsController(ILogger<TorrentsController> logger, Torrents tor
var results = await torrents.Get(); var results = await torrents.Get();
var torrentDtos = results.Select(torrent => new TorrentDto var torrentDtos = results.Select(torrent => new TorrentDto
{ {
TorrentId = torrent.TorrentId, TorrentId = torrent.TorrentId,
Hash = torrent.Hash, Hash = torrent.Hash,
Category = torrent.Category, Category = torrent.Category,
DownloadAction = torrent.DownloadAction, DownloadAction = torrent.DownloadAction,
FinishedAction = torrent.FinishedAction, FinishedAction = torrent.FinishedAction,
FinishedActionDelay = torrent.FinishedActionDelay, FinishedActionDelay = torrent.FinishedActionDelay,
HostDownloadAction = torrent.HostDownloadAction, HostDownloadAction = torrent.HostDownloadAction,
DownloadMinSize = torrent.DownloadMinSize, DownloadMinSize = torrent.DownloadMinSize,
IncludeRegex = torrent.IncludeRegex, IncludeRegex = torrent.IncludeRegex,
ExcludeRegex = torrent.ExcludeRegex, ExcludeRegex = torrent.ExcludeRegex,
DownloadManualFiles = torrent.DownloadManualFiles, DownloadManualFiles = torrent.DownloadManualFiles,
DownloadClient = torrent.DownloadClient, DownloadClient = torrent.DownloadClient,
Added = torrent.Added, Added = torrent.Added,
FilesSelected = torrent.FilesSelected, FilesSelected = torrent.FilesSelected,
Completed = torrent.Completed, Completed = torrent.Completed,
IsFile = torrent.IsFile, IsFile = torrent.IsFile,
Priority = torrent.Priority, Priority = torrent.Priority,
RetryCount = torrent.RetryCount, RetryCount = torrent.RetryCount,
DownloadRetryAttempts = torrent.DownloadRetryAttempts, DownloadRetryAttempts = torrent.DownloadRetryAttempts,
TorrentRetryAttempts = torrent.TorrentRetryAttempts, TorrentRetryAttempts = torrent.TorrentRetryAttempts,
DeleteOnError = torrent.DeleteOnError, DeleteOnError = torrent.DeleteOnError,
Lifetime = torrent.Lifetime, Lifetime = torrent.Lifetime,
Error = torrent.Error, Error = torrent.Error,
RdId = torrent.RdId, RdId = torrent.RdId,
RdName = torrent.RdName, RdName = torrent.RdName,
RdSize = torrent.RdSize, RdSize = torrent.RdSize,
RdHost = torrent.RdHost, RdHost = torrent.RdHost,
RdSplit = torrent.RdSplit, RdSplit = torrent.RdSplit,
RdProgress = torrent.RdProgress, RdProgress = torrent.RdProgress,
RdStatus = torrent.RdStatus, RdStatus = torrent.RdStatus,
RdStatusRaw = torrent.RdStatusRaw, RdStatusRaw = torrent.RdStatusRaw,
RdAdded = torrent.RdAdded, RdAdded = torrent.RdAdded,
RdEnded = torrent.RdEnded, RdEnded = torrent.RdEnded,
RdSpeed = torrent.RdSpeed, RdSpeed = torrent.RdSpeed,
RdSeeders = torrent.RdSeeders, RdSeeders = torrent.RdSeeders,
Files = torrent.Files, Files = torrent.Files,
Downloads = torrent.Downloads.Select(download => new DownloadDto Downloads = torrent.Downloads.Select(download => new DownloadDto
{ {
DownloadId = download.DownloadId, DownloadId = download.DownloadId,
TorrentId = download.TorrentId, TorrentId = download.TorrentId,
Path = download.Path, Path = download.Path,
Link = download.Link, Link = download.Link,
Added = download.Added, Added = download.Added,
DownloadQueued = download.DownloadQueued, DownloadQueued = download.DownloadQueued,
DownloadStarted = download.DownloadStarted, DownloadStarted = download.DownloadStarted,
DownloadFinished = download.DownloadFinished, DownloadFinished = download.DownloadFinished,
UnpackingQueued = download.UnpackingQueued, UnpackingQueued = download.UnpackingQueued,
UnpackingStarted = download.UnpackingStarted, UnpackingStarted = download.UnpackingStarted,
UnpackingFinished = download.UnpackingFinished, UnpackingFinished = download.UnpackingFinished,
Completed = download.Completed, Completed = download.Completed,
RetryCount = download.RetryCount, RetryCount = download.RetryCount,
Error = download.Error, Error = download.Error,
BytesTotal = download.BytesTotal, BytesTotal = download.BytesTotal,
BytesDone = download.BytesDone, BytesDone = download.BytesDone,
Speed = download.Speed Speed = download.Speed
}).ToList() })
}).ToList(); .ToList()
})
.ToList();
return Ok(torrentDtos); return Ok(torrentDtos);
} }
@ -138,26 +140,27 @@ public class TorrentsController(ILogger<TorrentsController> logger, Torrents tor
RdSpeed = torrent.RdSpeed, RdSpeed = torrent.RdSpeed,
RdSeeders = torrent.RdSeeders, RdSeeders = torrent.RdSeeders,
Files = torrent.Files, Files = torrent.Files,
Downloads = (torrent.Downloads).Select(download => new DownloadDto Downloads = torrent.Downloads.Select(download => new DownloadDto
{ {
DownloadId = download.DownloadId, DownloadId = download.DownloadId,
TorrentId = download.TorrentId, TorrentId = download.TorrentId,
Path = download.Path, Path = download.Path,
Link = download.Link, Link = download.Link,
Added = download.Added, Added = download.Added,
DownloadQueued = download.DownloadQueued, DownloadQueued = download.DownloadQueued,
DownloadStarted = download.DownloadStarted, DownloadStarted = download.DownloadStarted,
DownloadFinished = download.DownloadFinished, DownloadFinished = download.DownloadFinished,
UnpackingQueued = download.UnpackingQueued, UnpackingQueued = download.UnpackingQueued,
UnpackingStarted = download.UnpackingStarted, UnpackingStarted = download.UnpackingStarted,
UnpackingFinished = download.UnpackingFinished, UnpackingFinished = download.UnpackingFinished,
Completed = download.Completed, Completed = download.Completed,
RetryCount = download.RetryCount, RetryCount = download.RetryCount,
Error = download.Error, Error = download.Error,
BytesTotal = download.BytesTotal, BytesTotal = download.BytesTotal,
BytesDone = download.BytesDone, BytesDone = download.BytesDone,
Speed = download.Speed Speed = download.Speed
}).ToList() })
.ToList()
}; };
return Ok(torrentDto); return Ok(torrentDto);