diff --git a/src/backend/api/Fusion.Resources.Domain/Queries/GetPersonProfiles.cs b/src/backend/api/Fusion.Resources.Domain/Queries/GetPersonProfiles.cs index 87758b322..86f7590f2 100644 --- a/src/backend/api/Fusion.Resources.Domain/Queries/GetPersonProfiles.cs +++ b/src/backend/api/Fusion.Resources.Domain/Queries/GetPersonProfiles.cs @@ -19,7 +19,7 @@ public GetPersonProfiles(IEnumerable azureObjectIds) .ToList(); } - public List Identifiers { get; } + public List Identifiers { get; } public class Handler : IRequestHandler> { @@ -29,9 +29,20 @@ public Handler(IFusionProfileResolver profileResolver) { this.profileResolver = profileResolver; } - public async Task> Handle(GetPersonProfiles request, CancellationToken cancellationToken) + public async Task> Handle(GetPersonProfiles request, CancellationToken cancellationToken) { - var profiles = await profileResolver.ResolvePersonsAsync(request.Identifiers); + var tasks = new List>>(); + + // Max number of identifiers is 500, so we chunk the requests + foreach (var req in request.Identifiers.Chunk(500)) + { + tasks.Add(profileResolver.ResolvePersonsAsync(request.Identifiers)); + } + + var results = await Task.WhenAll(tasks); + + var profiles = results.Select(p => p).SelectMany(p => p); + return profiles .Where(p => p.Success && p.Profile?.AzureUniqueId != null) .ToDictionary(