Skip to content

Commit

Permalink
Minor patches to handle irregular database state (#36)
Browse files Browse the repository at this point in the history
* Handle destroyed gamespace during reset archive

* Filter out _initialscore_ challenges from list

* Minor cleanup in reset player
  • Loading branch information
sei-jbritton authored Jun 14, 2022
1 parent 5494a20 commit d114857
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/Gameboard.Api/Features/Challenge/ChallengeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ public async Task<ChallengeSummary[]> List(SearchFilter model)
{
var q = Store.List(model.Term);

// filter out challenge records with no state used to give starting score to player
q = q.Where(p => p.Name != "_initialscore_" && p.State != null);

q = q.OrderByDescending(p => p.LastSyncTime);

q = q.Skip(model.Skip);
Expand Down
16 changes: 13 additions & 3 deletions src/Gameboard.Api/Features/Player/PlayerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,16 +176,26 @@ public async Task<Player> Delete(string id, bool sudo = false)
.ToArrayAsync()
;
}
var toArchive = Mapper.Map<ArchivedChallenge[]>(challenges);
if (toArchive.Length > 0)

if (challenges.Count > 0)
{
var toArchive = Mapper.Map<ArchivedChallenge[]>(challenges);
var teamMembers = players.Select(a => a.UserId).ToArray();
foreach (var challenge in toArchive)
{
challenge.Submissions = (await Mojo.AuditChallengeAsync(challenge.Id)).ToArray();
// gamespace may be deleted in TopoMojo which would cause error and prevent reset
try
{
challenge.Submissions = (await Mojo.AuditChallengeAsync(challenge.Id)).ToArray();
}
catch
{
challenge.Submissions = new SectionSubmission[] {};
}
challenge.TeamMembers = teamMembers;
}
Store.DbContext.ArchivedChallenges.AddRange(Mapper.Map<Data.ArchivedChallenge[]>(toArchive));
await Store.DbContext.SaveChangesAsync();
}

// courtesy call; ignore error (gamespace may have already been removed from backend)
Expand Down

0 comments on commit d114857

Please sign in to comment.