Skip to content

Commit

Permalink
refactor: get wegsegment parallel db calls
Browse files Browse the repository at this point in the history
  • Loading branch information
jvandaal committed Feb 12, 2025
1 parent 041993a commit 07b2d04
Showing 1 changed file with 33 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,39 +61,53 @@ string GetStreetName(int? id)
return null;
}

var surfaceTypes = (await _editorContext.RoadSegmentSurfaceAttributes
var surfaceTask = _editorContext.RoadSegmentSurfaceAttributes
.Where(x => x.RoadSegmentId == roadSegment.Id)
.ToListAsync(cancellationToken: cancellationToken))
.ToListAsync(cancellationToken);

var widthTask = _editorContext.RoadSegmentWidthAttributes
.Where(x => x.RoadSegmentId == roadSegment.Id)
.ToListAsync(cancellationToken);

var laneTask = _editorContext.RoadSegmentLaneAttributes
.Where(x => x.RoadSegmentId == roadSegment.Id)
.ToListAsync(cancellationToken);

var europeanRoadTask = _editorContext.RoadSegmentEuropeanRoadAttributes
.Where(x => x.RoadSegmentId == roadSegment.Id)
.ToListAsync(cancellationToken);

var nationalRoadTask = _editorContext.RoadSegmentNationalRoadAttributes
.Where(x => x.RoadSegmentId == roadSegment.Id)
.ToListAsync(cancellationToken);

var numberedRoadTask = _editorContext.RoadSegmentNumberedRoadAttributes
.Where(x => x.RoadSegmentId == roadSegment.Id)
.ToListAsync(cancellationToken);

await Task.WhenAll(surfaceTask, widthTask, laneTask, europeanRoadTask, nationalRoadTask, numberedRoadTask);

var surfaceTypes = surfaceTask.Result
.Select(x => new RoadSegmentSurfaceAttributeDbaseRecord().FromBytes(x.DbaseRecord, _manager, _fileEncoding))
.ToList();

var widths = (await _editorContext.RoadSegmentWidthAttributes
.Where(x => x.RoadSegmentId == roadSegment.Id)
.ToListAsync(cancellationToken: cancellationToken))
var widths = widthTask.Result
.Select(x => new RoadSegmentWidthAttributeDbaseRecord().FromBytes(x.DbaseRecord, _manager, _fileEncoding))
.ToList();

var lanes = (await _editorContext.RoadSegmentLaneAttributes
.Where(x => x.RoadSegmentId == roadSegment.Id)
.ToListAsync(cancellationToken: cancellationToken))
var lanes = laneTask.Result
.Select(x => new RoadSegmentLaneAttributeDbaseRecord().FromBytes(x.DbaseRecord, _manager, _fileEncoding))
.ToList();

var europeanRoads = (await _editorContext.RoadSegmentEuropeanRoadAttributes
.Where(x => x.RoadSegmentId == roadSegment.Id)
.ToListAsync(cancellationToken: cancellationToken))
var europeanRoads = europeanRoadTask.Result
.Select(x => new RoadSegmentEuropeanRoadAttributeDbaseRecord().FromBytes(x.DbaseRecord, _manager, _fileEncoding))
.ToList();

var nationalRoads = (await _editorContext.RoadSegmentNationalRoadAttributes
.Where(x => x.RoadSegmentId == roadSegment.Id)
.ToListAsync(cancellationToken: cancellationToken))
var nationalRoads = nationalRoadTask.Result
.Select(x => new RoadSegmentNationalRoadAttributeDbaseRecord().FromBytes(x.DbaseRecord, _manager, _fileEncoding))
.ToList();

var numberedRoads = (await _editorContext.RoadSegmentNumberedRoadAttributes
.Where(x => x.RoadSegmentId == roadSegment.Id)
.ToListAsync(cancellationToken: cancellationToken))
var numberedRoads = numberedRoadTask.Result
.Select(x => new RoadSegmentNumberedRoadAttributeDbaseRecord().FromBytes(x.DbaseRecord, _manager, _fileEncoding))
.ToList();

Expand All @@ -102,7 +116,8 @@ string GetStreetName(int? id)
roadSegment.BeginTime,
roadSegment.Version,
roadSegment.LastEventHash
) {
)
{
Geometry = GeometryTranslator.Translate((MultiLineString)roadSegment.Geometry),
GeometryDrawMethod = RoadSegmentGeometryDrawMethod.ByIdentifier[roadSegment.MethodId],
StartNodeId = roadSegment.StartNodeId,
Expand Down

0 comments on commit 07b2d04

Please sign in to comment.