Skip to content

Commit 252b345

Browse files
committed
add duplicate replays report for maui
1 parent 5f035a9 commit 252b345

File tree

11 files changed

+56
-25
lines changed

11 files changed

+56
-25
lines changed

src/dsstats.db8services/Import/ImportService.Duplicates.cs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace dsstats.db8services.Import;
66

77
public partial class ImportService
88
{
9-
private async Task<int> HandleDuplicates(List<Replay> replays, ReplayContext context)
9+
private async Task<DupReport> HandleDuplicates(List<Replay> replays, ReplayContext context)
1010
{
1111
var replayHashes = replays.Select(s => s.ReplayHash).ToList();
1212
var dupReplays = await context.Replays
@@ -37,10 +37,29 @@ from rp in r.ReplayPlayers
3737

3838
dupReplays.AddRange(lsDupReplays);
3939
}
40+
else
41+
{
42+
var dupHashes = dupReplays
43+
.Select(s => s.ReplayHash)
44+
.ToHashSet();
45+
foreach (var replay in replays.ToArray())
46+
{
47+
if (dupHashes.Contains(replay.ReplayHash))
48+
{
49+
replays.Remove(replay);
50+
}
51+
}
52+
53+
return new()
54+
{
55+
Duplicates = dupReplays.Count,
56+
ReplayPaths = dupReplays.Select(s => s.FileName).ToHashSet()
57+
};
58+
}
4059

4160
if (dupReplays.Count == 0)
4261
{
43-
return 0;
62+
return new();
4463
}
4564

4665
int dupsHandled = 0;
@@ -74,7 +93,7 @@ from rp in r.ReplayPlayers
7493
}
7594
}
7695
await context.SaveChangesAsync();
77-
return dupsHandled;
96+
return new() { Duplicates = dupsHandled };
7897
}
7998

8099
private async Task<bool> HandleDuplicate(Replay dbReplay, Replay importReplay, ReplayContext context)
@@ -148,3 +167,9 @@ private async Task DeleteReplay(string replayHash, ReplayContext context)
148167
}
149168
}
150169
}
170+
171+
internal record DupReport
172+
{
173+
public int Duplicates { get; init; }
174+
public HashSet<string> ReplayPaths { get; init; } = [];
175+
}

src/dsstats.db8services/Import/ImportService.Import.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,13 @@ public async Task<ImportResult> Import(List<ReplayDto> replayDtos, List<PlayerId
102102

103103
string? error = null;
104104
int dups = 0;
105+
HashSet<string> duplicates = [];
105106
await importSs.WaitAsync();
106107
try
107108
{
108-
dups = await HandleDuplicates(replays, context);
109-
109+
var dupResult = await HandleDuplicates(replays, context);
110+
dups = dupResult.Duplicates;
111+
duplicates = dupResult.ReplayPaths;
110112
if (replays.Count > 0)
111113
{
112114
DateTime import = DateTime.UtcNow;
@@ -132,7 +134,10 @@ public async Task<ImportResult> Import(List<ReplayDto> replayDtos, List<PlayerId
132134
{
133135
Imported = replays.Count,
134136
Duplicates = dups,
135-
Error = error
137+
Error = error,
138+
DetailErrors = duplicates
139+
.Select(s => new KeyValuePair<string, string>(s, "Duplicate replay found."))
140+
.ToDictionary(kvp => kvp.Key, kvp => kvp.Value)
136141
};
137142
}
138143
}

src/dsstats.db8services/ReplayRepository.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,7 @@ public async Task SaveReplay(ReplayDto replayDto)
7373
dbReplay.Imported = DateTime.UtcNow;
7474
context.Replays.Add(dbReplay);
7575

76-
try
77-
{
78-
await context.SaveChangesAsync();
79-
}
80-
catch (Exception ex)
81-
{
82-
logger.LogError("failed saving replay: {error}", ex.Message);
83-
throw;
84-
}
76+
await context.SaveChangesAsync();
8577
}
8678

8779
private ICollection<SpawnUnit> GetMapedSpawnUnits(Spawn spawn, Commander commander)

src/dsstats.maui/dsstats.maui8/Platforms/Windows/Package.appxmanifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
66
IgnorableNamespaces="uap rescap">
77

8-
<Identity Name="29898PhilippHetzner.141231D0ED353" Publisher="CN=592AF738-4E2A-4BF3-87A7-D07953D08DE9" Version="2.0.10.0" />
8+
<Identity Name="29898PhilippHetzner.141231D0ED353" Publisher="CN=592AF738-4E2A-4BF3-87A7-D07953D08DE9" Version="2.1.0.0" />
99

1010
<Properties>
1111
<DisplayName>$placeholder$</DisplayName>

src/dsstats.maui/dsstats.maui8/Services/DsstatsService.DecodeJob.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using pax.dsstats.parser;
55
using s2protocol.NET;
66
using System.Collections.Concurrent;
7-
using System.Reflection;
87
using System.Security.Cryptography;
98

109
namespace dsstats.maui8.Services;
@@ -177,6 +176,18 @@ private async Task ImportReplays(bool flush = false)
177176
{
178177
errorReplays.AddRange(replaysToSave);
179178
}
179+
180+
foreach (var detailError in result.DetailErrors)
181+
{
182+
OnDecodeStateChanged(new()
183+
{
184+
DecodeError = new()
185+
{
186+
ReplayPath = detailError.Key,
187+
Error = detailError.Value
188+
}
189+
});
190+
}
180191
}
181192
}
182193
}
@@ -257,8 +268,7 @@ private ReplayDecoder GetDecoder()
257268
{
258269
if (decoder == null)
259270
{
260-
var _assemblyPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? "";
261-
decoder = new ReplayDecoder(_assemblyPath);
271+
decoder = new ReplayDecoder();
262272
}
263273
return decoder;
264274
}

src/dsstats.maui/dsstats.maui8/Services/GitHubUpdateService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace dsstats.maui8.Services;
66
public class GitHubUpdateService(ILogger<GitHubUpdateService> logger) : IUpdateService
77
{
88
private static readonly string packageUri = "https://github.com/ipax77/dsstats/releases/latest/download/";
9-
public static readonly Version CurrentVersion = new Version(2, 0, 10, 0);
9+
public static readonly Version CurrentVersion = new Version(2, 1, 0, 0);
1010
private Version latestVersion = new Version(0, 0, 0, 0);
1111
private readonly object lockobject = new();
1212
private readonly bool logToFile = false;

src/dsstats.maui/dsstats.maui8/dsstats.maui8.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@
7373
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.100" />
7474
<PackageReference Include="Microsoft.AspNetCore.Components.WebView.Maui" Version="8.0.100" />
7575
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.1" />
76-
<PackageReference Include="IronPython.StdLib" Version="2.7.12" />
7776
<PackageReference Include="Blazored.Toast" Version="4.2.1" />
7877
<PackageReference Include="CommunityToolkit.Maui" Version="9.1.1" />
7978
<PackageReference Include="System.Data.SqlClient" Version="4.9.0" />

src/dsstats.maui/pax.dsstats.parser/Parse.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public static async Task<Sc2Replay> GetSc2Replay(string replayPath, string? asse
106106
throw new ArgumentNullException(nameof(assemblyPath));
107107
}
108108

109-
ReplayDecoder decoder = new(assemblyPath);
109+
ReplayDecoder decoder = new();
110110

111111
ReplayDecoderOptions options = new ReplayDecoderOptions()
112112
{

src/dsstats.maui/pax.dsstats.parser/pax.dsstats.parser.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@
99

1010
<ItemGroup>
1111
<PackageReference Include="CsvHelper" Version="33.1.0" />
12-
<PackageReference Include="IronPython.StdLib" Version="2.7.12" />
13-
<PackageReference Include="s2protocol.NET" Version="0.8.4" />
1412
<PackageReference Include="System.Drawing.Common" Version="8.0.17" />
13+
<PackageReference Include="s2protocol.NET" Version="0.9.0" />
1514
</ItemGroup>
1615

1716
<ItemGroup>

src/dsstats.shared/Data.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1333,7 +1333,7 @@ public static (GameMode gameMode, int totalBans, int totalPicks) GetPickBanModeS
13331333

13341334
public const string ReplayBlobDir = "/data/ds/replayblobs";
13351335
public const string MysqlFilesDir = "/data/mysqlfiles";
1336-
public const string WasmVersion = "2.0.9";
1336+
public const string WasmVersion = "2.1.0";
13371337
}
13381338

13391339
public class LatestReplayEventArgs : EventArgs

0 commit comments

Comments
 (0)