Skip to content

Commit

Permalink
✨ Reduce Brouter Polylines (#2505)
Browse files Browse the repository at this point in the history
Co-authored-by: Kris <[email protected]>
  • Loading branch information
HerrLevin and MrKrisKrisu authored Apr 19, 2024
1 parent 1d1fbe3 commit 7babb35
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
11 changes: 9 additions & 2 deletions app/Http/Controllers/Backend/BrouterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ public static function reroutePolyline(Trip $trip): void {
if (App::runningUnitTests()) {
return;
}

//0. Check if brouter Polyline is already available
$polyline = PolyLine::where('parent_id', $trip->polyline_id)->orderBy('id', 'desc')->first();
if ($polyline?->source === 'brouter') {
Log::debug('[RefreshPolyline] Brouter Polyline already available for Trip#' . $trip->trip_id);
$trip->update(['polyline_id' => $polyline->id]);
return;
}

//1. Prepare coordinates from stations
$coordinates = [];
foreach ($trip->stopovers as $stopover) {
Expand Down Expand Up @@ -121,8 +130,6 @@ public static function reroutePolyline(Trip $trip): void {
$properties = [
'id' => $stopover->station->ibnr,
'name' => $stopover->station->name,
'departure_planned' => $stopover->departure_planned,
'arrival_planned' => $stopover->arrival_planned,
];

//Get feature with the lowest distance to station
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
public function up(): void {
Schema::table('poly_lines', static function (Blueprint $table) {
$table->index('parent_id');
});
}

public function down(): void {
Schema::table('poly_lines', static function (Blueprint $table) {
$table->dropIndex(['parent_id']);
});
}
};

0 comments on commit 7babb35

Please sign in to comment.