From e1765db6cdfadc7365fab78a373ebd7f0984aff7 Mon Sep 17 00:00:00 2001 From: Aleksander Lund Date: Wed, 20 Sep 2023 14:34:10 +0200 Subject: [PATCH 1/2] Chunking 500 at the time when getting PersonProfile from PeopleAPI --- .../Queries/GetPersonProfiles.cs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/backend/api/Fusion.Resources.Domain/Queries/GetPersonProfiles.cs b/src/backend/api/Fusion.Resources.Domain/Queries/GetPersonProfiles.cs index 87758b322..b53f8364b 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(X => X).SelectMany(o => o); + return profiles .Where(p => p.Success && p.Profile?.AzureUniqueId != null) .ToDictionary( From a008328b7872a77611bfd8e7f7b221807a05bf8f Mon Sep 17 00:00:00 2001 From: Aleksander Lund Date: Wed, 20 Sep 2023 15:01:37 +0200 Subject: [PATCH 2/2] Fixed variablename --- .../api/Fusion.Resources.Domain/Queries/GetPersonProfiles.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/api/Fusion.Resources.Domain/Queries/GetPersonProfiles.cs b/src/backend/api/Fusion.Resources.Domain/Queries/GetPersonProfiles.cs index b53f8364b..86f7590f2 100644 --- a/src/backend/api/Fusion.Resources.Domain/Queries/GetPersonProfiles.cs +++ b/src/backend/api/Fusion.Resources.Domain/Queries/GetPersonProfiles.cs @@ -41,7 +41,7 @@ public async Task> Handle(GetPersonProfile var results = await Task.WhenAll(tasks); - var profiles = results.Select(X => X).SelectMany(o => o); + var profiles = results.Select(p => p).SelectMany(p => p); return profiles .Where(p => p.Success && p.Profile?.AzureUniqueId != null)