mirror of
https://github.com/MrUnknownDE/panel.git
synced 2026-04-12 03:13:45 +02:00
Return all servers for a node as a paginated response
Avoids crashing the PHP process and avoids a bad runaway N+1 query issue that previously existed.
This commit is contained in:
35
app/Http/Resources/Wings/ServerConfigurationCollection.php
Normal file
35
app/Http/Resources/Wings/ServerConfigurationCollection.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Http\Resources\Wings;
|
||||
|
||||
use Pterodactyl\Models\Server;
|
||||
use Illuminate\Container\Container;
|
||||
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||
use Pterodactyl\Services\Eggs\EggConfigurationService;
|
||||
use Pterodactyl\Services\Servers\ServerConfigurationStructureService;
|
||||
|
||||
class ServerConfigurationCollection extends ResourceCollection
|
||||
{
|
||||
/**
|
||||
* Converts a collection of Server models into an array of configuration responses
|
||||
* that can be understood by Wings. Make sure you've properly loaded the required
|
||||
* relationships on the Server models before calling this function, otherwise you'll
|
||||
* have some serious performance issues from all of the N+1 queries.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
$egg = Container::getInstance()->make(EggConfigurationService::class);
|
||||
$configuration = Container::getInstance()->make(ServerConfigurationStructureService::class);
|
||||
|
||||
return $this->collection->map(function (Server $server) use ($configuration, $egg) {
|
||||
return [
|
||||
'uuid' => $server->uuid,
|
||||
'settings' => $configuration->handle($server),
|
||||
'process_configuration' => $egg->handle($server),
|
||||
];
|
||||
})->toArray();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user