perf(SymlinkDownloader): Skip file search when using Alldebrid
This commit is contained in:
parent
8fe277fa52
commit
38a3bc1537
2 changed files with 23 additions and 5 deletions
|
|
@ -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.Internal => new InternalDownloader(download.Link, filePath),
|
||||||
Data.Enums.DownloadClient.Bezzad => new BezzadDownloader(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.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}")
|
_ => throw new($"Unknown download client {Type}")
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
using RdtClient.Service.Helpers;
|
using RdtClient.Data.Models.Data;
|
||||||
|
using RdtClient.Service.Helpers;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
|
|
||||||
namespace RdtClient.Service.Services.Downloaders;
|
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<DownloadCompleteEventArgs>? DownloadComplete;
|
||||||
public event EventHandler<DownloadProgressEventArgs>? DownloadProgress;
|
public event EventHandler<DownloadProgressEventArgs>? DownloadProgress;
|
||||||
|
|
@ -57,6 +58,22 @@ public class SymlinkDownloader(String uri, String destinationPath, String path)
|
||||||
Speed = 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 };
|
var potentialFilePaths = new List<String> { searchPath };
|
||||||
|
|
||||||
var directoryInfo = new DirectoryInfo(searchPath);
|
var directoryInfo = new DirectoryInfo(searchPath);
|
||||||
|
|
@ -78,8 +95,6 @@ public class SymlinkDownloader(String uri, String destinationPath, String path)
|
||||||
|
|
||||||
potentialFilePaths = potentialFilePaths.Distinct().ToList();
|
potentialFilePaths = potentialFilePaths.Distinct().ToList();
|
||||||
|
|
||||||
String? file = null;
|
|
||||||
|
|
||||||
for (var retryCount = 0; retryCount < MaxRetries; retryCount++)
|
for (var retryCount = 0; retryCount < MaxRetries; retryCount++)
|
||||||
{
|
{
|
||||||
DownloadProgress?.Invoke(this,
|
DownloadProgress?.Invoke(this,
|
||||||
|
|
@ -136,6 +151,9 @@ public class SymlinkDownloader(String uri, String destinationPath, String path)
|
||||||
throw new("Could not find file from rclone mount!");
|
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}");
|
_logger.Debug($"Creating symbolic link from {file} to {destinationPath}");
|
||||||
|
|
||||||
var result = TryCreateSymbolicLink(file, destinationPath);
|
var result = TryCreateSymbolicLink(file, destinationPath);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue