check cold storage outside of download task instead

This commit is contained in:
Loporrit
2024-08-30 08:32:55 +00:00
parent 05c880d4e8
commit fb0905ef84

View File

@@ -55,9 +55,6 @@ public sealed class CachedFileProvider : IDisposable
{ {
var destinationFilePath = FilePathUtil.GetFilePath(_hotStoragePath, hash); var destinationFilePath = FilePathUtil.GetFilePath(_hotStoragePath, hash);
// first check cold storage
if (TryCopyFromColdStorage(hash, destinationFilePath)) return;
// if cold storage is not configured or file not found or error is present try to download file from remote // if cold storage is not configured or file not found or error is present try to download file from remote
var downloadUrl = MareFiles.DistributionGetFullPath(_remoteCacheSourceUri, hash); var downloadUrl = MareFiles.DistributionGetFullPath(_remoteCacheSourceUri, hash);
_logger.LogInformation("Did not find {hash}, downloading from {server}", hash, downloadUrl); _logger.LogInformation("Did not find {hash}, downloading from {server}", hash, downloadUrl);
@@ -134,10 +131,10 @@ public sealed class CachedFileProvider : IDisposable
public async Task DownloadFileWhenRequired(string hash) public async Task DownloadFileWhenRequired(string hash)
{ {
var fi = FilePathUtil.GetFileInfoForHash(_hotStoragePath, hash); var fi = FilePathUtil.GetFileInfoForHash(_hotStoragePath, hash);
if (fi == null && IsMainServer) if (fi == null)
{ {
TryCopyFromColdStorage(hash, FilePathUtil.GetFilePath(_hotStoragePath, hash)); if (TryCopyFromColdStorage(hash, FilePathUtil.GetFilePath(_hotStoragePath, hash)))
return; return;
} }
await _downloadSemaphore.WaitAsync().ConfigureAwait(false); await _downloadSemaphore.WaitAsync().ConfigureAwait(false);