perf(SymlinkDownloader): Skip file search when using Alldebrid

This commit is contained in:
Sculas 2025-01-07 14:34:02 +01:00
parent 8fe277fa52
commit 38a3bc1537
No known key found for this signature in database
GPG key ID: 1530BFF96D1EEB89
2 changed files with 23 additions and 5 deletions

View file

@ -51,7 +51,7 @@ public class DownloadClient(Download download, Torrent torrent, String destinati
Data.Enums.DownloadClient.Internal => new InternalDownloader(download.Link, filePath),
Data.Enums.DownloadClient.Bezzad => new BezzadDownloader(download.Link, filePath),
Data.Enums.DownloadClient.Aria2c => new Aria2cDownloader(download.RemoteId, download.Link, filePath, downloadPath, category),
Data.Enums.DownloadClient.Symlink => new SymlinkDownloader(download.Link, filePath, downloadPath),
Data.Enums.DownloadClient.Symlink => new SymlinkDownloader(download.Link, filePath, downloadPath, torrent.ClientKind),
_ => throw new($"Unknown download client {Type}")
};

View file

@ -1,9 +1,10 @@
using RdtClient.Service.Helpers;
using RdtClient.Data.Models.Data;
using RdtClient.Service.Helpers;
using Serilog;
namespace RdtClient.Service.Services.Downloaders;
public class SymlinkDownloader(String uri, String destinationPath, String path) : IDownloader
public class SymlinkDownloader(String uri, String destinationPath, String path, Torrent.TorrentClientKind? clientKind) : IDownloader
{
public event EventHandler<DownloadCompleteEventArgs>? DownloadComplete;
public event EventHandler<DownloadProgressEventArgs>? DownloadProgress;
@ -56,6 +57,22 @@ public class SymlinkDownloader(String uri, String destinationPath, String path)
BytesTotal = 0,
Speed = 0
});
String? file = null;
// When resolving symlinks for AllDebrid, we know the exact file path, so we can skip the search.
if (clientKind == Torrent.TorrentClientKind.AllDebrid)
{
var potentialFilePath = Path.Combine(rcloneMountPath, path);
// Make sure the file exists before making any assumptions.
// If this somehow fails, fallback to the search below.
if (File.Exists(potentialFilePath))
{
file = potentialFilePath;
goto skipFileSearch;
}
}
var potentialFilePaths = new List<String> { searchPath };
@ -78,8 +95,6 @@ public class SymlinkDownloader(String uri, String destinationPath, String path)
potentialFilePaths = potentialFilePaths.Distinct().ToList();
String? file = null;
for (var retryCount = 0; retryCount < MaxRetries; retryCount++)
{
DownloadProgress?.Invoke(this,
@ -135,6 +150,9 @@ public class SymlinkDownloader(String uri, String destinationPath, String path)
throw new("Could not find file from rclone mount!");
}
// Used by Alldebrid since we know the exact file path.
skipFileSearch:
_logger.Debug($"Creating symbolic link from {file} to {destinationPath}");