@@ -6,7 +6,7 @@ namespace dsstats.db8services.Import;
66
77public 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+ }
0 commit comments