Merge branch 'next' into authentik

This commit is contained in:
🏔️ Peak
2024-12-11 17:52:02 +01:00
committed by GitHub
3 changed files with 88 additions and 122 deletions

View File

@@ -14,7 +14,7 @@ class Migration extends Command
{ {
if (config('constants.migration.is_migration_enabled')) { if (config('constants.migration.is_migration_enabled')) {
$this->info('Migration is enabled on this server.'); $this->info('Migration is enabled on this server.');
$this->call('migrate --force --isolated'); $this->call('migrate', ['--force' => true, '--isolated' => true]);
exit(0); exit(0);
} else { } else {
$this->info('Migration is disabled on this server.'); $this->info('Migration is disabled on this server.');

View File

@@ -46,125 +46,84 @@ class Index extends Component
return redirect()->route('dashboard'); return redirect()->route('dashboard');
} }
$this->project = $project; $this->project = $project;
$this->environment = $environment; $this->environment = $environment->loadCount([
$this->applications = $this->environment->applications->load(['tags']); 'applications',
'redis',
'postgresqls',
'mysqls',
'keydbs',
'dragonflies',
'clickhouses',
'mariadbs',
'mongodbs',
'services',
]);
// Eager load all relationships for applications including nested ones
$this->applications = $this->environment->applications()->with([
'tags',
'additional_servers.settings',
'additional_networks',
'destination.server.settings',
'settings',
])->get()->sortBy('name');
$this->applications = $this->applications->map(function ($application) { $this->applications = $this->applications->map(function ($application) {
if (data_get($application, 'environment.project.uuid')) { $application->hrefLink = route('project.application.configuration', [
$application->hrefLink = route('project.application.configuration', [ 'project_uuid' => $this->project->uuid,
'project_uuid' => data_get($application, 'environment.project.uuid'), 'application_uuid' => $application->uuid,
'environment_name' => data_get($application, 'environment.name'), 'environment_name' => $this->environment->name,
'application_uuid' => data_get($application, 'uuid'), ]);
]);
}
return $application; return $application;
}); });
$this->postgresqls = $this->environment->postgresqls->load(['tags'])->sortBy('name');
$this->postgresqls = $this->postgresqls->map(function ($postgresql) {
if (data_get($postgresql, 'environment.project.uuid')) {
$postgresql->hrefLink = route('project.database.configuration', [
'project_uuid' => data_get($postgresql, 'environment.project.uuid'),
'environment_name' => data_get($postgresql, 'environment.name'),
'database_uuid' => data_get($postgresql, 'uuid'),
]);
}
return $postgresql; // Load all database resources in a single query per type
}); $databaseTypes = [
$this->redis = $this->environment->redis->load(['tags'])->sortBy('name'); 'postgresqls' => 'postgresqls',
$this->redis = $this->redis->map(function ($redis) { 'redis' => 'redis',
if (data_get($redis, 'environment.project.uuid')) { 'mongodbs' => 'mongodbs',
$redis->hrefLink = route('project.database.configuration', [ 'mysqls' => 'mysqls',
'project_uuid' => data_get($redis, 'environment.project.uuid'), 'mariadbs' => 'mariadbs',
'environment_name' => data_get($redis, 'environment.name'), 'keydbs' => 'keydbs',
'database_uuid' => data_get($redis, 'uuid'), 'dragonflies' => 'dragonflies',
]); 'clickhouses' => 'clickhouses',
} ];
return $redis; // Load all server-related data first to prevent duplicate queries
}); $serverData = $this->environment->applications()
$this->mongodbs = $this->environment->mongodbs->load(['tags'])->sortBy('name'); ->with(['destination.server.settings'])
$this->mongodbs = $this->mongodbs->map(function ($mongodb) { ->get()
if (data_get($mongodb, 'environment.project.uuid')) { ->pluck('destination.server')
$mongodb->hrefLink = route('project.database.configuration', [ ->filter()
'project_uuid' => data_get($mongodb, 'environment.project.uuid'), ->unique('id');
'environment_name' => data_get($mongodb, 'environment.name'),
'database_uuid' => data_get($mongodb, 'uuid'),
]);
}
return $mongodb; foreach ($databaseTypes as $property => $relation) {
}); $this->{$property} = $this->environment->{$relation}()->with([
$this->mysqls = $this->environment->mysqls->load(['tags'])->sortBy('name'); 'tags',
$this->mysqls = $this->mysqls->map(function ($mysql) { 'destination.server.settings',
if (data_get($mysql, 'environment.project.uuid')) { ])->get()->sortBy('name');
$mysql->hrefLink = route('project.database.configuration', [ $this->{$property} = $this->{$property}->map(function ($db) {
'project_uuid' => data_get($mysql, 'environment.project.uuid'), $db->hrefLink = route('project.database.configuration', [
'environment_name' => data_get($mysql, 'environment.name'), 'project_uuid' => $this->project->uuid,
'database_uuid' => data_get($mysql, 'uuid'), 'database_uuid' => $db->uuid,
'environment_name' => $this->environment->name,
]); ]);
}
return $mysql; return $db;
}); });
$this->mariadbs = $this->environment->mariadbs->load(['tags'])->sortBy('name'); }
$this->mariadbs = $this->mariadbs->map(function ($mariadb) {
if (data_get($mariadb, 'environment.project.uuid')) {
$mariadb->hrefLink = route('project.database.configuration', [
'project_uuid' => data_get($mariadb, 'environment.project.uuid'),
'environment_name' => data_get($mariadb, 'environment.name'),
'database_uuid' => data_get($mariadb, 'uuid'),
]);
}
return $mariadb; // Load services with their tags and server
}); $this->services = $this->environment->services()->with([
$this->keydbs = $this->environment->keydbs->load(['tags'])->sortBy('name'); 'tags',
$this->keydbs = $this->keydbs->map(function ($keydb) { 'destination.server.settings',
if (data_get($keydb, 'environment.project.uuid')) { ])->get()->sortBy('name');
$keydb->hrefLink = route('project.database.configuration', [
'project_uuid' => data_get($keydb, 'environment.project.uuid'),
'environment_name' => data_get($keydb, 'environment.name'),
'database_uuid' => data_get($keydb, 'uuid'),
]);
}
return $keydb;
});
$this->dragonflies = $this->environment->dragonflies->load(['tags'])->sortBy('name');
$this->dragonflies = $this->dragonflies->map(function ($dragonfly) {
if (data_get($dragonfly, 'environment.project.uuid')) {
$dragonfly->hrefLink = route('project.database.configuration', [
'project_uuid' => data_get($dragonfly, 'environment.project.uuid'),
'environment_name' => data_get($dragonfly, 'environment.name'),
'database_uuid' => data_get($dragonfly, 'uuid'),
]);
}
return $dragonfly;
});
$this->clickhouses = $this->environment->clickhouses->load(['tags'])->sortBy('name');
$this->clickhouses = $this->clickhouses->map(function ($clickhouse) {
if (data_get($clickhouse, 'environment.project.uuid')) {
$clickhouse->hrefLink = route('project.database.configuration', [
'project_uuid' => data_get($clickhouse, 'environment.project.uuid'),
'environment_name' => data_get($clickhouse, 'environment.name'),
'database_uuid' => data_get($clickhouse, 'uuid'),
]);
}
return $clickhouse;
});
$this->services = $this->environment->services->load(['tags'])->sortBy('name');
$this->services = $this->services->map(function ($service) { $this->services = $this->services->map(function ($service) {
if (data_get($service, 'environment.project.uuid')) { $service->hrefLink = route('project.service.configuration', [
$service->hrefLink = route('project.service.configuration', [ 'project_uuid' => $this->project->uuid,
'project_uuid' => data_get($service, 'environment.project.uuid'), 'service_uuid' => $service->uuid,
'environment_name' => data_get($service, 'environment.name'), 'environment_name' => $this->environment->name,
'service_uuid' => data_get($service, 'uuid'), ]);
]);
$service->status = $service->status();
}
return $service; return $service;
}); });

View File

@@ -115,6 +115,12 @@ class Application extends BaseModel
protected static function booted() protected static function booted()
{ {
static::addGlobalScope('withRelations', function ($builder) {
$builder->withCount([
'additional_servers',
'additional_networks',
]);
});
static::saving(function ($application) { static::saving(function ($application) {
$payload = []; $payload = [];
if ($application->isDirty('fqdn')) { if ($application->isDirty('fqdn')) {
@@ -551,20 +557,21 @@ class Application extends BaseModel
{ {
return Attribute::make( return Attribute::make(
get: function () { get: function () {
if ($this->additional_servers->count() === 0) { if (! $this->relationLoaded('additional_servers') || $this->additional_servers->count() === 0) {
return $this->destination->server->isFunctional(); return $this->destination?->server?->isFunctional() ?? false;
} else {
$additional_servers_status = $this->additional_servers->pluck('pivot.status');
$main_server_status = $this->destination->server->isFunctional();
foreach ($additional_servers_status as $status) {
$server_status = str($status)->before(':')->value();
if ($server_status !== 'running') {
return false;
}
}
return $main_server_status;
} }
$additional_servers_status = $this->additional_servers->pluck('pivot.status');
$main_server_status = $this->destination?->server?->isFunctional() ?? false;
foreach ($additional_servers_status as $status) {
$server_status = str($status)->before(':')->value();
if ($server_status !== 'running') {
return false;
}
}
return $main_server_status;
} }
); );
} }