refactor(environment): streamline environment variable handling by replacing sorting methods with direct property access and enhancing query ordering for improved performance

This commit is contained in:
Andras Bacsai
2025-09-12 12:09:03 +02:00
parent c6b47da1e9
commit 8e155f25b3
12 changed files with 108 additions and 43 deletions

View File

@@ -728,7 +728,14 @@ class Application extends BaseModel
{
return $this->morphMany(EnvironmentVariable::class, 'resourceable')
->where('is_preview', false)
->orderBy('key', 'asc');
->orderByRaw("
CASE
WHEN LOWER(key) LIKE 'service_%' THEN 1
WHEN is_required = true AND (value IS NULL OR value = '') THEN 2
ELSE 3
END,
LOWER(key) ASC
");
}
public function runtime_environment_variables()
@@ -749,7 +756,14 @@ class Application extends BaseModel
{
return $this->morphMany(EnvironmentVariable::class, 'resourceable')
->where('is_preview', true)
->orderByRaw("LOWER(key) LIKE LOWER('SERVICE%') DESC, LOWER(key) ASC");
->orderByRaw("
CASE
WHEN LOWER(key) LIKE 'service_%' THEN 1
WHEN is_required = true AND (value IS NULL OR value = '') THEN 2
ELSE 3
END,
LOWER(key) ASC
");
}
public function runtime_environment_variables_preview()