Skip to content

Commit

Permalink
feat(replays): Update replay unpacker to 3.0 + Dependent refactors
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
SakuraIsayeki committed May 18, 2024
1 parent ff664be commit f57db9d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
13 changes: 9 additions & 4 deletions WowsKarma.Api/Data/Models/Replays/Replay.cs
Original file line number Diff line number Diff line change
@@ -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; }
Expand All @@ -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<ReplayPlayer> Players { get; set; } = [];

[Column(TypeName = "jsonb")]
public IEnumerable<ReplayChatMessage> ChatMessages { get; set; } = [];

/// <inheritdoc />
public void Dispose()
{
ArenaInfo.Dispose();
}
}
6 changes: 3 additions & 3 deletions WowsKarma.Api/Services/Replays/ReplaysProcessService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public sealed class ReplaysProcessService
IgnoreReadOnlyProperties = true
};

private readonly IReplayUnpackerService _replayUnpacker;
private readonly IReplayUnpackerService<ExtendedDataReplay> _replayUnpacker;
private readonly ApiDbContext _context;

public ReplaysProcessService(ReplayUnpackerFactory replayUnpacker, ApiDbContext context)
Expand All @@ -49,9 +49,9 @@ public Task<Replay> 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
{
Expand Down
2 changes: 1 addition & 1 deletion WowsKarma.Api/WowsKarma.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<PackageReference Include="Microsoft.Extensions.Hosting.Systemd" Version="8.0.0" />
<PackageReference Include="NodaTime" Version="3.1.11" />
<PackageReference Include="Nodsoft.Wargaming.Api.Client" Version="0.3.5" />
<PackageReference Include="Nodsoft.WowsReplaysUnpack.ExtendedData" Version="2.0.4" />
<PackageReference Include="Nodsoft.WowsReplaysUnpack.ExtendedData" Version="3.0.7-beta-g06221c5d51" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.2" />
<PackageReference Include="Polly.Extensions" Version="8.3.1" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.1" />
Expand Down

0 comments on commit f57db9d

Please sign in to comment.