Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/chunkGettingPersonProfiles #591

Merged
merged 2 commits into from
Sep 20, 2023
Merged
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 @@ -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
Loading