From 1c809c9984e7bd901789ea1e380b00886d5c5040 Mon Sep 17 00:00:00 2001 From: csavelief Date: Thu, 30 May 2024 15:11:11 +0200 Subject: [PATCH] Improve performances while loading the list of servers. --- app/Models/YnhServer.php | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/app/Models/YnhServer.php b/app/Models/YnhServer.php index b4c9c73..508b2ee 100644 --- a/app/Models/YnhServer.php +++ b/app/Models/YnhServer.php @@ -158,15 +158,14 @@ public function status(): ServerStatusEnum // Check if status is running $minDate = Carbon::today()->subMinutes(10); $isRunning = collect(DB::select(" - SELECT CASE WHEN MAX(t.count) IS NULL THEN 0 ELSE 1 END AS count - FROM ( - SELECT 1 AS count + 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 name IN ('memory_available_snapshot', 'disk_available_snapshot') - AND calendar_time >= '{$minDate->toDateTimeString()}' - LIMIT 1 - ) AS t + ) + AND calendar_time >= '{$minDate->toDateTimeString()}' "))->first(); if ($isRunning->count > 0) { @@ -177,15 +176,14 @@ public function status(): ServerStatusEnum // Check if status is unknown $minDate = $minDate->subMinutes(10); $isUnknown = collect(DB::select(" - SELECT CASE WHEN MAX(t.count) IS NULL THEN 0 ELSE 1 END AS count - FROM ( - SELECT 1 AS count + 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 name IN ('memory_available_snapshot', 'disk_available_snapshot') - AND calendar_time >= '{$minDate->toDateTimeString()}' - LIMIT 1 - ) AS t + ) + AND calendar_time >= '{$minDate->toDateTimeString()}' "))->first(); if ($isUnknown->count > 0) {