Skip to content

Commit

Permalink
refac: Improve performance of getting actors. (#1596)
Browse files Browse the repository at this point in the history
* refac: Improve performance of getting actors.

* Update tests.
  • Loading branch information
defectiveAi authored Mar 30, 2023
1 parent f242211 commit 444de22
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ limitations under the License.

<ItemGroup>
<PackageReference Include="WireMock.Net" Version="1.5.13" />
<PackageReference Include="Energinet.DataHub.Core.TestCommon" Version="4.0.0" />
<PackageReference Include="Energinet.DataHub.Core.FunctionApp.TestCommon" Version="4.0.0" />
<PackageReference Include="Energinet.DataHub.Core.TestCommon" Version="4.0.2" />
<PackageReference Include="Energinet.DataHub.Core.FunctionApp.TestCommon" Version="4.0.2" />
<PackageReference Include="Energinet.DataHub.MeteringPoints.Client" Version="3.0.1" />
<PackageReference Include="FluentAssertions" Version="6.8.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="6.0.12" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public async Task GetFilteredActors_NotFas_ReturnsSingleActor(OrganizationDto or
.ReturnsAsync(organizations);

MarketParticipantClientMock
.Setup(client => client.GetActorsAsync(organization.OrganizationId))
.Setup(client => client.GetActorsAsync())
.ReturnsAsync(actors);

MarketParticipantClientMock
Expand Down Expand Up @@ -118,7 +118,7 @@ public async Task GetFilteredActors_IsFas_ReturnsAllActors(OrganizationDto organ
.ReturnsAsync(organizations);

MarketParticipantClientMock
.Setup(client => client.GetActorsAsync(organization.OrganizationId))
.Setup(client => client.GetActorsAsync())
.ReturnsAsync(actors);

MarketParticipantClientMock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,19 @@ public Task<ActionResult<IEnumerable<OrganizationWithActorsDto>>> GetAllOrganiza
.GetOrganizationsAsync()
.ConfigureAwait(false);

var result = new List<OrganizationWithActorsDto>();
var allActors = await _client
.GetActorsAsync()
.ConfigureAwait(false);

var groupByOrganization = allActors.ToLookup(a => a.OrganizationId);

foreach (var organization in organizations)
var result = organizations.Select(organization =>
{
var actors = await _client.GetActorsAsync(organization.OrganizationId);
result.Add(new OrganizationWithActorsDto(organization, actors));
}
var actors = groupByOrganization[organization.OrganizationId];
return new OrganizationWithActorsDto(organization, actors);
});

return (IEnumerable<OrganizationWithActorsDto>)result;
return result;
});
}

Expand Down Expand Up @@ -121,17 +125,10 @@ public Task<ActionResult<IEnumerable<FilteredActorDto>>> GetFilteredActorsAsync(
var gridAreas = await _client.GetGridAreasAsync().ConfigureAwait(false);
var gridAreaLookup = gridAreas.ToDictionary(x => x.Id);

var organizations = await _client
.GetOrganizationsAsync()
var actors = await _client
.GetActorsAsync()
.ConfigureAwait(false);

var actors = new List<ActorDto>();

foreach (var organizationDto in organizations)
{
actors.AddRange(await _client.GetActorsAsync(organizationDto.OrganizationId).ConfigureAwait(false));
}

var accessibleActors = actors
.Select(x =>
new FilteredActorDto(
Expand Down
6 changes: 3 additions & 3 deletions apps/dh/api-dh/source/DataHub.WebApi/DataHub.WebApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ limitations under the License.
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.21.0" />
<PackageReference Include="Energinet.DataHub.Charges.Clients" Version="6.1.0" />
<PackageReference Include="Energinet.DataHub.Charges.Clients.Registration" Version="6.1.0" />
<PackageReference Include="Energinet.DataHub.Core.App.Common.Security" Version="7.4.0" />
<PackageReference Include="Energinet.DataHub.Core.App.WebApp" Version="7.4.0" />
<PackageReference Condition="!Exists('$(MarketingParticipantProjectReference)')" Include="Energinet.DataHub.MarketParticipant.Client" Version="2.29.4" />
<PackageReference Include="Energinet.DataHub.Core.App.Common.Security" Version="7.4.1" />
<PackageReference Include="Energinet.DataHub.Core.App.WebApp" Version="7.4.1" />
<PackageReference Condition="!Exists('$(MarketingParticipantProjectReference)')" Include="Energinet.DataHub.MarketParticipant.Client" Version="2.29.6" />
<PackageReference Condition="!Exists('$(MessageArchiveClientAbstractionsProjectReference)')" Include="Energinet.DataHub.MessageArchive.Client" Version="2.0.8" />
<PackageReference Condition="!Exists('$(MessageArchiveClientProjectReference)')" Include="Energinet.DataHub.MessageArchive.Client.Abstractions" Version="2.0.8" />
<PackageReference Include="Energinet.DataHub.MeteringPoints.Client" Version="3.0.1" />
Expand Down

0 comments on commit 444de22

Please sign in to comment.