From 1305ba56b09038e5ff63b6f2b3c6b28584cc86f4 Mon Sep 17 00:00:00 2001 From: H01001000 Date: Fri, 12 Dec 2025 21:26:40 -0800 Subject: [PATCH] fix: use object instead, cause laravel dont pass array by ref --- app/Actions/Docker/GetContainersStatus.php | 3 ++- app/Actions/Shared/ComplexStatusCheck.php | 17 +++++++++++++---- app/Actions/Shared/DockerInspectCache.php | 8 ++++++++ app/Jobs/PushServerUpdateJob.php | 3 ++- 4 files changed, 25 insertions(+), 6 deletions(-) create mode 100644 app/Actions/Shared/DockerInspectCache.php diff --git a/app/Actions/Docker/GetContainersStatus.php b/app/Actions/Docker/GetContainersStatus.php index f34c8e4c9..a144ece3c 100644 --- a/app/Actions/Docker/GetContainersStatus.php +++ b/app/Actions/Docker/GetContainersStatus.php @@ -4,6 +4,7 @@ namespace App\Actions\Docker; use App\Actions\Database\StartDatabaseProxy; use App\Actions\Shared\ComplexStatusCheck; +use App\Actions\Shared\DockerInspectCache; use App\Events\ServiceChecked; use App\Models\ApplicationPreview; use App\Models\Server; @@ -46,7 +47,7 @@ class GetContainersStatus } $this->applications = $this->server->applications(); $skip_these_applications = collect([]); - $dockerInspectCache = []; + $dockerInspectCache = new DockerInspectCache(); foreach ($this->applications as $application) { if ($application->additional_servers->count() > 0) { $skip_these_applications->push($application); diff --git a/app/Actions/Shared/ComplexStatusCheck.php b/app/Actions/Shared/ComplexStatusCheck.php index 3d37ea8d4..52905838e 100644 --- a/app/Actions/Shared/ComplexStatusCheck.php +++ b/app/Actions/Shared/ComplexStatusCheck.php @@ -5,15 +5,22 @@ namespace App\Actions\Shared; use App\Models\Application; use App\Services\ContainerStatusAggregator; use App\Traits\CalculatesExcludedStatus; +use App\Actions\Shared\DockerInspectCache; use Lorisleiva\Actions\Concerns\AsAction; +use Illuminate\Support\Facades\Log; class ComplexStatusCheck { use AsAction; use CalculatesExcludedStatus; - public function handle(Application $application, array &$dockerInspectCache = []) + public function handle(Application $application, DockerInspectCache $dockerInspectCache = new DockerInspectCache()) { + Log::info('Docker inspect cache size', [ + 'entries' => count($dockerInspectCache->data), + ]); + dump('Cache entries b4:', count($dockerInspectCache->data)); + $servers = $application->additional_servers; $servers->push($application->destination->server); foreach ($servers as $server) { @@ -30,12 +37,12 @@ class ComplexStatusCheck } } - if (!isset($dockerInspectCache[$server->id])) { + if (!isset($dockerInspectCache->data[$server->id])) { $allContainers = instant_remote_process(["docker container inspect $(docker ps -aq --filter 'label=coolify.pullRequestId=0') --format 'json'"], $server, false); $allContainers = format_docker_command_output_to_json($allContainers); - $dockerInspectCache[$server->id] = $allContainers; + $dockerInspectCache->data[$server->id] = $allContainers; } - $allContainers = $dockerInspectCache[$server->id]; + $allContainers = $dockerInspectCache->data[$server->id]; $containers = collect($allContainers)->filter(function ($container) use ($application) { $labels = data_get($container, 'Config.Labels', []); @@ -71,6 +78,8 @@ class ComplexStatusCheck } } } + + dump('Cache entries after:', count($dockerInspectCache->data)); } private function aggregateContainerStatuses($application, $containers) diff --git a/app/Actions/Shared/DockerInspectCache.php b/app/Actions/Shared/DockerInspectCache.php new file mode 100644 index 000000000..0f8303e56 --- /dev/null +++ b/app/Actions/Shared/DockerInspectCache.php @@ -0,0 +1,8 @@ +allApplicationsWithAdditionalServers->each(function ($application) { ComplexStatusCheck::run($application, $dockerInspectCache); });