fix: parrellel safe changes

This commit is contained in:
tresabhi committed 2025-03-05 09:56:49 -06:00
1 parent 2fffd512ac
commit 6e8fdcfeef
2 files changed
+12 -9

No files matched your search

-2
View File
@@ -134,8 +134,6 @@ namespace BlitzKit.CLI.Functions
// MangleHull(id, pda);
Console.WriteLine(slug);
Tank tank = new()
{
Id = id,
+12 -7
View File
@@ -1,3 +1,4 @@
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Net;
using BlitzKit.CLI.Utils;
@@ -41,7 +42,8 @@ namespace BlitzKit.CLI.Models
{
Credentials = new(Env.GetString("GH_TOKEN")),
};
List<FileChange> changes = [];
var seenPaths = new ConcurrentDictionary<string, bool>();
var changes = new ConcurrentBag<FileChange>(); // Thread-safe alternative
await Task.WhenAll(
changesRaw
@@ -55,16 +57,19 @@ namespace BlitzKit.CLI.Models
if (response.StatusCode == HttpStatusCode.NotFound)
{
Console.WriteLine(
$"🟢 (+{change.Content.Count.ToString("N0", Program.Culture)}B) {blobPath}"
);
changes.Add(change);
if (seenPaths.TryAdd(change.Path, true)) // Ensures uniqueness
{
Console.WriteLine(
$"🟢 (+{change.Content.Count.ToString("N0", Program.Culture)}B) {blobPath}"
);
changes.Add(change);
}
}
else if (response.StatusCode == HttpStatusCode.OK)
{
var bytes = await response.Content.ReadAsByteArrayAsync();
if (!bytes.SequenceEqual([.. change.Content]))
if (!bytes.SequenceEqual([.. change.Content]) && seenPaths.TryAdd(change.Path, true))
{
var diff = change.Content.Count - bytes.Length;
@@ -83,7 +88,7 @@ namespace BlitzKit.CLI.Models
.ToList()
);
if (changes.Count == 0)
if (changes.IsEmpty)
return;
var repoRawSplit = repoRaw.Split('/');