fix: use object instead, cause laravel dont pass array by ref

This commit is contained in:
H01001000 2025-12-12 21:26:40 -08:00
parent 5a34f180eb
commit 1305ba56b0
No known key found for this signature in database
GPG key ID: 3794A5F6B719C5DF
4 changed files with 25 additions and 6 deletions

View file

@ -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);

View file

@ -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)

View file

@ -0,0 +1,8 @@
<?php
namespace App\Actions\Shared;
class DockerInspectCache
{
public array $data = [];
}

View file

@ -8,6 +8,7 @@ use App\Actions\Proxy\CheckProxy;
use App\Actions\Proxy\StartProxy;
use App\Actions\Server\StartLogDrain;
use App\Actions\Shared\ComplexStatusCheck;
use App\Actions\Shared\DockerInspectCache;
use App\Models\Application;
use App\Models\Server;
use App\Models\ServiceApplication;
@ -580,7 +581,7 @@ class PushServerUpdateJob implements ShouldBeEncrypted, ShouldQueue, Silenced
private function updateAdditionalServersStatus()
{
$dockerInspectCache = [];
$dockerInspectCache = new DockerInspectCache();
$this->allApplicationsWithAdditionalServers->each(function ($application) {
ComplexStatusCheck::run($application, $dockerInspectCache);
});