From f57db9d0c408207d1924b4b5c388a2bdbdb81b19 Mon Sep 17 00:00:00 2001 From: Sakura Akeno Isayeki Date: Sat, 18 May 2024 11:26:09 +0200 Subject: [PATCH] feat(replays): Update replay unpacker to 3.0 + Dependent refactors - Added `JsonDocument` property `ArenaInfo` to the `Replay` model. - Updated `ReplaysProcessService` to serialize and store the `ArenaInfo` as a JSON document. - Upgraded `Nodsoft.WowsReplaysUnpack.ExtendedData` package to version 3.0.7-beta-g06221c5d51 in the project file. --- WowsKarma.Api/Data/Models/Replays/Replay.cs | 13 +++++++++---- .../Services/Replays/ReplaysProcessService.cs | 6 +++--- WowsKarma.Api/WowsKarma.Api.csproj | 2 +- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/WowsKarma.Api/Data/Models/Replays/Replay.cs b/WowsKarma.Api/Data/Models/Replays/Replay.cs index 849f4b5..6568693 100644 --- a/WowsKarma.Api/Data/Models/Replays/Replay.cs +++ b/WowsKarma.Api/Data/Models/Replays/Replay.cs @@ -1,11 +1,12 @@ using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using System.Text.Json; using Nodsoft.WowsReplaysUnpack.Core.Models; namespace WowsKarma.Api.Data.Models.Replays; -public sealed record Replay +public sealed record Replay : IDisposable { [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)] public Guid Id { get; init; } @@ -22,13 +23,17 @@ public sealed record Replay /* * Replay content (stored JSON) */ - - [Column(TypeName = "jsonb")] - public ArenaInfo ArenaInfo { get; set; } = null!; + public JsonDocument ArenaInfo { get; set; } = null!; [Column(TypeName = "jsonb")] public IEnumerable Players { get; set; } = []; [Column(TypeName = "jsonb")] public IEnumerable ChatMessages { get; set; } = []; + + /// + public void Dispose() + { + ArenaInfo.Dispose(); + } } diff --git a/WowsKarma.Api/Services/Replays/ReplaysProcessService.cs b/WowsKarma.Api/Services/Replays/ReplaysProcessService.cs index 7a1c44a..1db0915 100644 --- a/WowsKarma.Api/Services/Replays/ReplaysProcessService.cs +++ b/WowsKarma.Api/Services/Replays/ReplaysProcessService.cs @@ -23,7 +23,7 @@ public sealed class ReplaysProcessService IgnoreReadOnlyProperties = true }; - private readonly IReplayUnpackerService _replayUnpacker; + private readonly IReplayUnpackerService _replayUnpacker; private readonly ApiDbContext _context; public ReplaysProcessService(ReplayUnpackerFactory replayUnpacker, ApiDbContext context) @@ -49,9 +49,9 @@ public Task ProcessReplayAsync(Replay replay, Stream replayStream, Cance { ct.ThrowIfCancellationRequested(); - ExtendedDataReplay replayRaw = (ExtendedDataReplay)_replayUnpacker.Unpack(replayStream); + ExtendedDataReplay replayRaw = _replayUnpacker.Unpack(replayStream); - replay.ArenaInfo = replayRaw.ArenaInfo; + replay.ArenaInfo = JsonSerializer.SerializeToDocument(replayRaw.ArenaInfo); replay.Players = ProcessReplayPlayers(replayRaw.ReplayPlayers); replay.ChatMessages = replayRaw.ChatMessages.Select(m => new ReplayChatMessage { diff --git a/WowsKarma.Api/WowsKarma.Api.csproj b/WowsKarma.Api/WowsKarma.Api.csproj index 47d4d74..cb5207c 100644 --- a/WowsKarma.Api/WowsKarma.Api.csproj +++ b/WowsKarma.Api/WowsKarma.Api.csproj @@ -51,7 +51,7 @@ - +