*atomize* download status!
This commit is contained in:
@@ -18,8 +18,7 @@ namespace LightlessSync.WebAPI.Files;
|
||||
|
||||
public partial class FileDownloadManager : DisposableMediatorSubscriberBase
|
||||
{
|
||||
private readonly Dictionary<string, FileDownloadStatus> _downloadStatus;
|
||||
private readonly object _downloadStatusLock = new();
|
||||
private readonly ConcurrentDictionary<string, FileDownloadStatus> _downloadStatus;
|
||||
|
||||
private readonly FileCompactor _fileCompactor;
|
||||
private readonly FileCacheManager _fileDbManager;
|
||||
@@ -46,7 +45,7 @@ public partial class FileDownloadManager : DisposableMediatorSubscriberBase
|
||||
ModelDecimationService modelDecimationService,
|
||||
TextureMetadataHelper textureMetadataHelper) : base(logger, mediator)
|
||||
{
|
||||
_downloadStatus = new Dictionary<string, FileDownloadStatus>(StringComparer.Ordinal);
|
||||
_downloadStatus = new ConcurrentDictionary<string, FileDownloadStatus>(StringComparer.Ordinal);
|
||||
_orchestrator = orchestrator;
|
||||
_fileDbManager = fileCacheManager;
|
||||
_fileCompactor = fileCompactor;
|
||||
@@ -86,10 +85,7 @@ public partial class FileDownloadManager : DisposableMediatorSubscriberBase
|
||||
public void ClearDownload()
|
||||
{
|
||||
CurrentDownloads.Clear();
|
||||
lock (_downloadStatusLock)
|
||||
{
|
||||
_downloadStatus.Clear();
|
||||
}
|
||||
_downloadStatus.Clear();
|
||||
CurrentOwnerToken = null;
|
||||
}
|
||||
|
||||
@@ -156,29 +152,20 @@ public partial class FileDownloadManager : DisposableMediatorSubscriberBase
|
||||
|
||||
private void SetStatus(string key, DownloadStatus status)
|
||||
{
|
||||
lock (_downloadStatusLock)
|
||||
{
|
||||
if (_downloadStatus.TryGetValue(key, out var st))
|
||||
st.DownloadStatus = status;
|
||||
}
|
||||
if (_downloadStatus.TryGetValue(key, out var st))
|
||||
st.DownloadStatus = status;
|
||||
}
|
||||
|
||||
private void AddTransferredBytes(string key, long delta)
|
||||
{
|
||||
lock (_downloadStatusLock)
|
||||
{
|
||||
if (_downloadStatus.TryGetValue(key, out var st))
|
||||
st.TransferredBytes += delta;
|
||||
}
|
||||
if (_downloadStatus.TryGetValue(key, out var st))
|
||||
st.AddTransferredBytes(delta);
|
||||
}
|
||||
|
||||
private void MarkTransferredFiles(string key, int files)
|
||||
{
|
||||
lock (_downloadStatusLock)
|
||||
{
|
||||
if (_downloadStatus.TryGetValue(key, out var st))
|
||||
st.TransferredFiles = files;
|
||||
}
|
||||
if (_downloadStatus.TryGetValue(key, out var st))
|
||||
st.SetTransferredFiles(files);
|
||||
}
|
||||
|
||||
private static byte MungeByte(int byteOrEof)
|
||||
@@ -712,34 +699,31 @@ public partial class FileDownloadManager : DisposableMediatorSubscriberBase
|
||||
.ToArray();
|
||||
|
||||
// init statuses
|
||||
lock (_downloadStatusLock)
|
||||
_downloadStatus.Clear();
|
||||
|
||||
// direct downloads and batch downloads tracked separately
|
||||
foreach (var d in directDownloads)
|
||||
{
|
||||
_downloadStatus.Clear();
|
||||
|
||||
// direct downloads and batch downloads tracked separately
|
||||
foreach (var d in directDownloads)
|
||||
_downloadStatus[d.DirectDownloadUrl!] = new FileDownloadStatus
|
||||
{
|
||||
_downloadStatus[d.DirectDownloadUrl!] = new FileDownloadStatus
|
||||
{
|
||||
DownloadStatus = DownloadStatus.WaitingForSlot,
|
||||
TotalBytes = d.Total,
|
||||
TotalFiles = 1,
|
||||
TransferredBytes = 0,
|
||||
TransferredFiles = 0
|
||||
};
|
||||
}
|
||||
DownloadStatus = DownloadStatus.WaitingForSlot,
|
||||
TotalBytes = d.Total,
|
||||
TotalFiles = 1,
|
||||
TransferredBytes = 0,
|
||||
TransferredFiles = 0
|
||||
};
|
||||
}
|
||||
|
||||
foreach (var chunk in batchChunks)
|
||||
foreach (var chunk in batchChunks)
|
||||
{
|
||||
_downloadStatus[chunk.StatusKey] = new FileDownloadStatus
|
||||
{
|
||||
_downloadStatus[chunk.StatusKey] = new FileDownloadStatus
|
||||
{
|
||||
DownloadStatus = DownloadStatus.WaitingForQueue,
|
||||
TotalBytes = chunk.Items.Sum(x => x.Total),
|
||||
TotalFiles = 1,
|
||||
TransferredBytes = 0,
|
||||
TransferredFiles = 0
|
||||
};
|
||||
}
|
||||
DownloadStatus = DownloadStatus.WaitingForQueue,
|
||||
TotalBytes = chunk.Items.Sum(x => x.Total),
|
||||
TotalFiles = 1,
|
||||
TransferredBytes = 0,
|
||||
TransferredFiles = 0
|
||||
};
|
||||
}
|
||||
|
||||
if (directDownloads.Count > 0 || batchChunks.Length > 0)
|
||||
|
||||
Reference in New Issue
Block a user