sigma update

This commit is contained in:
2026-01-16 11:00:58 +09:00
parent 59ed03a825
commit 96123d00a2
51 changed files with 6640 additions and 1382 deletions

View File

@@ -0,0 +1,48 @@
using System.Collections.Concurrent;
namespace LightlessSync.WebAPI.Files;
public readonly record struct DownloadClaim(bool IsOwner, Task<bool> Completion);
public sealed class FileDownloadDeduplicator
{
private readonly ConcurrentDictionary<string, TaskCompletionSource<bool>> _inFlight =
new(StringComparer.OrdinalIgnoreCase);
public DownloadClaim Claim(string hash)
{
if (string.IsNullOrWhiteSpace(hash))
{
return new DownloadClaim(false, Task.FromResult(true));
}
var tcs = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
var existing = _inFlight.GetOrAdd(hash, tcs);
var isOwner = ReferenceEquals(existing, tcs);
return new DownloadClaim(isOwner, existing.Task);
}
public void Complete(string hash, bool success)
{
if (string.IsNullOrWhiteSpace(hash))
{
return;
}
if (_inFlight.TryRemove(hash, out var tcs))
{
tcs.TrySetResult(success);
}
}
public void CompleteAll(bool success)
{
foreach (var entry in _inFlight.ToArray())
{
if (_inFlight.TryRemove(entry.Key, out var tcs))
{
tcs.TrySetResult(success);
}
}
}
}

File diff suppressed because it is too large Load Diff