Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,32 @@
public async Task<Dictionary<int, DiscordXIVUser?>> GetUsersFromActors(
IEnumerable<LogInfo.ReportDataWrapper.ReportData.Report.Master.Actor> actors)
{
// Map to dict of actor ID to potential DB user
var potentialUsers = actors.ToDictionary(a => a.Id, a => a)
.Select(async kvp => new
.Select(kvp => new
{
ActorId = kvp.Key,
User = await _db.GetUserByCharacterInfo(kvp.Value.Server, kvp.Value.Name),
User = new PotentialDbUser(kvp.Value.Name, kvp.Value.Server),
})
.ToList();
var potentialUsersAwaited = await Task.WhenAll(potentialUsers);
var users = potentialUsersAwaited
.Where(kvp => kvp.User != null)
.ToDictionary(kvp => kvp.ActorId, kvp => kvp.User);

// Dedupe by world/name to minimize DB queries since the same user can show up as many actors
var dedupedUsersForQuery = potentialUsers.Select(kvp => kvp.User)
.DistinctBy(u => u.ToString())
.Select(u => _db.GetUserByCharacterInfo(u.World, u.Name))
.ToList();
var dedupedUsersForQueryAwaited = await Task.WhenAll(dedupedUsersForQuery);

// Reshape to dict of potential DB user to real DB user
var dedupedUsersForQueryDict = dedupedUsersForQueryAwaited
.Where(u => u != null)
.ToDictionary(u => new PotentialDbUser(u.Name, u.World).ToString());

Check warning on line 38 in src/Prima.Application/Commands/FFXIV/DelubrumReginae/CommandBatchActorMapper.cs

View workflow job for this annotation

GitHub Actions / dotnet_build

Dereference of a possibly null reference.

// Build dict of actor ID to real DB user
var users = potentialUsers
.ToDictionary(
kvp => kvp.ActorId,
kvp => dedupedUsersForQueryDict.GetValueOrDefault(kvp.User.ToString()));
return users;
}
}
5 changes: 5 additions & 0 deletions src/Prima/Game/FFXIV/PotentialDbUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,10 @@ public PotentialDbUser(string name, string world, DiscordXIVUser? user = null)
World = world;
User = user;
}

public override string ToString()
{
return $"({World}) {Name}";
}
}
}
2 changes: 1 addition & 1 deletion src/Prima/Services/DbService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class DbService : IDbService
{
private const string ConnectionString = "mongodb://localhost:27017";
private const string DbName = "PrimaDb";
private const double LockTimeoutSeconds = 30;
private const double LockTimeoutSeconds = 120;

// Hide types of the database implementation from callers.
public GlobalConfiguration Config
Expand Down
Loading