mirror of
https://github.com/tiennm99/coolify.git
synced 2026-04-17 23:20:43 +00:00
fix(performance): eliminate N+1 query in CheckTraefikVersionJob
This commit fixes a critical N+1 query issue in CheckTraefikVersionJob that was loading ALL proxy servers into memory then filtering in PHP, causing potential OOM errors with thousands of servers. Changes: - Added scopeWhereProxyType() query scope to Server model for database-level filtering using JSON column arrow notation - Updated CheckTraefikVersionJob to use new scope instead of collection filter, moving proxy type filtering into the SQL query - Added comprehensive unit tests for the new query scope Performance impact: - Before: SELECT * FROM servers WHERE proxy IS NOT NULL (all servers) - After: SELECT * FROM servers WHERE proxy->>'type' = 'TRAEFIK' (filtered) - Eliminates memory overhead of loading non-Traefik servers - Critical for cloud instances with thousands of connected servers 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -47,10 +47,10 @@ class CheckTraefikVersionJob implements ShouldQueue
|
||||
|
||||
// Query all servers with Traefik proxy that are reachable
|
||||
$servers = Server::whereNotNull('proxy')
|
||||
->whereProxyType(ProxyTypes::TRAEFIK->value)
|
||||
->whereRelation('settings', 'is_reachable', true)
|
||||
->whereRelation('settings', 'is_usable', true)
|
||||
->get()
|
||||
->filter(fn ($server) => $server->proxyType() === ProxyTypes::TRAEFIK->value);
|
||||
->get();
|
||||
|
||||
$serverCount = $servers->count();
|
||||
Log::info("CheckTraefikVersionJob: Found {$serverCount} server(s) with Traefik proxy");
|
||||
|
||||
Reference in New Issue
Block a user