Avoid N+1 location query for servers

This commit is contained in:
Dane Everitt 2020-10-31 11:28:31 -07:00
parent c00e5b36a5
commit ff64220741
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53

View file

@ -5,6 +5,7 @@ namespace Pterodactyl\Http\Controllers\Api\Remote\Servers;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Pterodactyl\Models\Server; use Pterodactyl\Models\Server;
use Illuminate\Http\JsonResponse; use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\DB;
use Pterodactyl\Http\Controllers\Controller; use Pterodactyl\Http\Controllers\Controller;
use Pterodactyl\Repositories\Eloquent\NodeRepository; use Pterodactyl\Repositories\Eloquent\NodeRepository;
use Pterodactyl\Services\Eggs\EggConfigurationService; use Pterodactyl\Services\Eggs\EggConfigurationService;
@ -81,7 +82,7 @@ class ServerDetailsController extends Controller
// Avoid run-away N+1 SQL queries by pre-loading the relationships that are used // Avoid run-away N+1 SQL queries by pre-loading the relationships that are used
// within each of the services called below. // within each of the services called below.
$servers = Server::query()->with('allocations', 'egg', 'mounts', 'variables') $servers = Server::query()->with('allocations', 'egg', 'mounts', 'variables', 'location')
->where('node_id', $node->id) ->where('node_id', $node->id)
->paginate($request->input('per_page', 50)); ->paginate($request->input('per_page', 50));