mirror of
https://github.com/coollabsio/coolify.git
synced 2025-12-28 05:34:50 +00:00
- Eager load service applications and databases to eliminate N+1 queries
- Replace individual model updates with batch database updates for applications, previews, and services
- Move connectProxyToNetworks to async ConnectProxyToNetworksJob to avoid blocking status updates
- Optimize Server.databases() and applications() methods with efficient database queries
- Use flatMap for cleaner collection transformations
🤖 Generated with Claude Code
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
56 lines
1.6 KiB
PHP
56 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs;
|
|
|
|
use App\Models\Server;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Contracts\Queue\ShouldBeEncrypted;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
use Illuminate\Queue\Middleware\WithoutOverlapping;
|
|
use Illuminate\Queue\SerializesModels;
|
|
use Laravel\Horizon\Contracts\Silenced;
|
|
|
|
/**
|
|
* Asynchronously connects the coolify-proxy to Docker networks.
|
|
*
|
|
* This job is dispatched from PushServerUpdateJob when the proxy is found running
|
|
* to ensure it's connected to all required networks without blocking the status update.
|
|
*/
|
|
class ConnectProxyToNetworksJob implements ShouldBeEncrypted, ShouldQueue, Silenced
|
|
{
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
public $tries = 1;
|
|
|
|
public $timeout = 60;
|
|
|
|
public function middleware(): array
|
|
{
|
|
// Prevent overlapping executions for the same server and throttle to max once per 10 seconds
|
|
return [
|
|
(new WithoutOverlapping('connect-proxy-networks-'.$this->server->uuid))
|
|
->expireAfter(60)
|
|
->dontRelease(),
|
|
];
|
|
}
|
|
|
|
public function __construct(public Server $server) {}
|
|
|
|
public function handle()
|
|
{
|
|
if (! $this->server->isFunctional()) {
|
|
return;
|
|
}
|
|
|
|
$connectProxyToDockerNetworks = connectProxyToNetworks($this->server);
|
|
|
|
if (empty($connectProxyToDockerNetworks)) {
|
|
return;
|
|
}
|
|
|
|
instant_remote_process($connectProxyToDockerNetworks, $this->server, false);
|
|
}
|
|
}
|