Skip to content

Commit

Permalink
Improve performances while loading the list of servers.
Browse files Browse the repository at this point in the history
  • Loading branch information
csavelief committed May 30, 2024
1 parent 448be4f commit 1c809c9
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions app/Models/YnhServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit 1c809c9

Please sign in to comment.