From ae881708f5deecffa4197b9401f51ffc365ad368 Mon Sep 17 00:00:00 2001 From: csavelief Date: Thu, 30 May 2024 15:48:18 +0200 Subject: [PATCH] Servers - Carbon::now() is better than Carbon:today() because both the current date and time are set. --- app/Models/YnhServer.php | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/app/Models/YnhServer.php b/app/Models/YnhServer.php index 508b2ee..5df5ac6 100644 --- a/app/Models/YnhServer.php +++ b/app/Models/YnhServer.php @@ -156,16 +156,12 @@ public function status(): ServerStatusEnum } // Check if status is running - $minDate = Carbon::today()->subMinutes(10); + $minDate = Carbon::now()->subMinutes(10); $isRunning = collect(DB::select(" - SELECT CASE WHEN MAX(id) IS NULL THEN 0 ELSE 1 END AS count - FROM ynh_osquery - WHERE id IN ( - SELECT MAX(id) AS id - FROM ynh_osquery - WHERE ynh_server_id = {$this->id} - ) - AND calendar_time >= '{$minDate->toDateTimeString()}' + SELECT COUNT(id) AS count + FROM ynh_osquery + WHERE ynh_server_id = {$this->id} + AND calendar_time >= '{$minDate->toDateTimeString()}' "))->first(); if ($isRunning->count > 0) { @@ -176,14 +172,10 @@ public function status(): ServerStatusEnum // Check if status is unknown $minDate = $minDate->subMinutes(10); $isUnknown = collect(DB::select(" - SELECT CASE WHEN MAX(id) IS NULL THEN 0 ELSE 1 END AS count - FROM ynh_osquery - WHERE id IN ( - SELECT MAX(id) AS id - FROM ynh_osquery - WHERE ynh_server_id = {$this->id} - ) - AND calendar_time >= '{$minDate->toDateTimeString()}' + SELECT COUNT(id) AS count + FROM ynh_osquery + WHERE ynh_server_id = {$this->id} + AND calendar_time >= '{$minDate->toDateTimeString()}' "))->first(); if ($isUnknown->count > 0) {