From 7babb353055b6fe7bea5a351aa6042ddc8da6695 Mon Sep 17 00:00:00 2001 From: Levin Herr Date: Fri, 19 Apr 2024 23:05:24 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Reduce=20Brouter=20Polylines=20(#25?= =?UTF-8?q?05)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Kris --- .../Controllers/Backend/BrouterController.php | 11 ++++++++-- ...31906_add_index_to_poly_line_parent_id.php | 20 +++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 database/migrations/2024_04_19_131906_add_index_to_poly_line_parent_id.php diff --git a/app/Http/Controllers/Backend/BrouterController.php b/app/Http/Controllers/Backend/BrouterController.php index 6435e0121..8a93b9808 100644 --- a/app/Http/Controllers/Backend/BrouterController.php +++ b/app/Http/Controllers/Backend/BrouterController.php @@ -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) { @@ -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 diff --git a/database/migrations/2024_04_19_131906_add_index_to_poly_line_parent_id.php b/database/migrations/2024_04_19_131906_add_index_to_poly_line_parent_id.php new file mode 100644 index 000000000..c21e3a8c7 --- /dev/null +++ b/database/migrations/2024_04_19_131906_add_index_to_poly_line_parent_id.php @@ -0,0 +1,20 @@ +index('parent_id'); + }); + } + + public function down(): void { + Schema::table('poly_lines', static function (Blueprint $table) { + $table->dropIndex(['parent_id']); + }); + } +};