Skip to content

Commit

Permalink
Chunking 500 at the time when getting PersonProfile from PeopleAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
aleklundeq committed Sep 20, 2023
1 parent 9b016d8 commit e1765db
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(X => X).SelectMany(o => o);

return profiles
.Where(p => p.Success && p.Profile?.AzureUniqueId != null)
.ToDictionary(
Expand Down

0 comments on commit e1765db

Please sign in to comment.