Skip to content

Commit

Permalink
Fix bug cycle when downloading data
Browse files Browse the repository at this point in the history
  • Loading branch information
Simyon264 committed Aug 30, 2024
1 parent 1148e2f commit b0566a3
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions ReplayBrowser/Controllers/AccountController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,17 +230,24 @@ [FromQuery] string guid
var historyEntry = archive.CreateEntry("history.json");
using (var entryStream = historyEntry.Open())
{
await JsonSerializer.SerializeAsync(entryStream, user.History);
await JsonSerializer.SerializeAsync(entryStream, user.History, new JsonSerializerOptions()
{
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
ReferenceHandler = ReferenceHandler.IgnoreCycles,
WriteIndented = true
});
}

user.History = [];

var baseEntry = archive.CreateEntry("user.json");
using (var entryStream = baseEntry.Open())
{
await JsonSerializer.SerializeAsync(entryStream, user, new JsonSerializerOptions
await JsonSerializer.SerializeAsync(entryStream, user, new JsonSerializerOptions()
{
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
ReferenceHandler = ReferenceHandler.IgnoreCycles,
WriteIndented = true
});
}
}
Expand All @@ -256,10 +263,11 @@ [FromQuery] string guid
var replayEntry = archive.CreateEntry($"replay-{replay.Id}.json");
using (var entryStream = replayEntry.Open())
{
await JsonSerializer.SerializeAsync(entryStream, replay, new JsonSerializerOptions
await JsonSerializer.SerializeAsync(entryStream, replay, new JsonSerializerOptions()
{
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
ReferenceHandler = ReferenceHandler.IgnoreCycles
ReferenceHandler = ReferenceHandler.IgnoreCycles,
WriteIndented = true
});
}
}
Expand Down Expand Up @@ -424,7 +432,12 @@ public async Task<IActionResult> DownloadAccount()
var historyEntry = archive.CreateEntry("history.json");
using (var entryStream = historyEntry.Open())
{
await JsonSerializer.SerializeAsync(entryStream, user.History);
await JsonSerializer.SerializeAsync(entryStream, user.History, new JsonSerializerOptions()
{
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
ReferenceHandler = ReferenceHandler.IgnoreCycles,
WriteIndented = true
});
}

user.History = [];
Expand All @@ -434,7 +447,9 @@ public async Task<IActionResult> DownloadAccount()
{
await JsonSerializer.SerializeAsync(entryStream, user, new JsonSerializerOptions
{
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
ReferenceHandler = ReferenceHandler.IgnoreCycles,
WriteIndented = true
});
}
}
Expand Down

0 comments on commit b0566a3

Please sign in to comment.