Skip to content

Commit

Permalink
feat/chunkGettingPersonProfiles (#591)
Browse files Browse the repository at this point in the history
* Chunking 500 at the time when getting PersonProfile from PeopleAPI

* Fixed variablename
  • Loading branch information
aleklundeq authored Sep 20, 2023
1 parent 9b016d8 commit 972bbe2
Showing 1 changed file with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public GetPersonProfiles(IEnumerable<Guid> azureObjectIds)
.ToList();
}

public List<PersonIdentifier> Identifiers { get; }
public List<PersonIdentifier> Identifiers { get; }

public class Handler : IRequestHandler<GetPersonProfiles, Dictionary<Guid, FusionPersonProfile>>
{
Expand All @@ -29,9 +29,20 @@ public Handler(IFusionProfileResolver profileResolver)
{
this.profileResolver = profileResolver;
}
public async Task<Dictionary<Guid,FusionPersonProfile>> Handle(GetPersonProfiles request, CancellationToken cancellationToken)
public async Task<Dictionary<Guid, FusionPersonProfile>> Handle(GetPersonProfiles request, CancellationToken cancellationToken)
{
var profiles = await profileResolver.ResolvePersonsAsync(request.Identifiers);
var tasks = new List<Task<IEnumerable<ResolvedPersonProfile>>>();

// 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(
Expand Down

0 comments on commit 972bbe2

Please sign in to comment.