Skip to content

Commit c63ef18

Browse files
committed
feat(challenge): allow recalculate submission count for teams
1 parent 10c3ebc commit c63ef18

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/GZCTF/Repositories/GameChallengeRepository.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public async Task<bool> RecalculateAcceptedCount(Game game, CancellationToken to
117117
.GroupBy(i => i.ChallengeId)
118118
.Select(g => new { ChallengeId = g.Key, Count = g.Count() });
119119

120-
await Context.GameChallenges.IgnoreAutoIncludes()
120+
await Context.GameChallenges.AsNoTracking().IgnoreAutoIncludes()
121121
.Where(c => query.Any(r => r.ChallengeId == c.Id))
122122
.ExecuteUpdateAsync(
123123
setter =>
@@ -126,8 +126,24 @@ await Context.GameChallenges.IgnoreAutoIncludes()
126126
c => query.First(r => r.ChallengeId == c.Id).Count),
127127
token);
128128

129-
await cacheHelper.FlushScoreboardCache(game.Id, token);
129+
var attempts = Context.Submissions.AsNoTracking()
130+
.IgnoreAutoIncludes()
131+
.Where(s => s.GameId == game.Id)
132+
.GroupBy(s => new { s.ChallengeId, s.ParticipationId })
133+
.Select(g => new { g.Key.ChallengeId, g.Key.ParticipationId, Count = g.Count() });
134+
135+
await Context.GameInstances.AsNoTracking().IgnoreAutoIncludes()
136+
.Where(i => attempts.Any(a =>
137+
a.ChallengeId == i.ChallengeId && a.ParticipationId == i.ParticipationId))
138+
.ExecuteUpdateAsync(
139+
setter => setter.SetProperty(
140+
i => i.SubmissionCount,
141+
i => attempts.First(a =>
142+
a.ChallengeId == i.ChallengeId && a.ParticipationId == i.ParticipationId).Count),
143+
token);
144+
130145
await trans.CommitAsync(token);
146+
await cacheHelper.FlushScoreboardCache(game.Id, token);
131147
}
132148
catch
133149
{

0 commit comments

Comments
 (0)