Fix SQL call
This commit is contained in:
parent
1216f950e2
commit
281337943f
1 changed files with 7 additions and 6 deletions
|
@ -31,17 +31,18 @@ class NodeRepository extends EloquentRepository implements NodeRepositoryInterfa
|
||||||
*/
|
*/
|
||||||
public function getUsageStats($id)
|
public function getUsageStats($id)
|
||||||
{
|
{
|
||||||
$node = $this->getBuilder()->select(
|
$node = $this->getBuilder()->select([
|
||||||
'nodes.disk_overallocate',
|
'nodes.disk_overallocate',
|
||||||
'nodes.memory_overallocate',
|
'nodes.memory_overallocate',
|
||||||
'nodes.disk',
|
'nodes.disk',
|
||||||
'nodes.memory',
|
'nodes.memory',
|
||||||
$this->getBuilder()->raw('SUM(servers.memory) as sum_memory, SUM(servers.disk) as sum_disk')
|
])->where('id', $id)->first();
|
||||||
)->join('servers', 'servers.node_id', '=', 'nodes.id')
|
|
||||||
->where('nodes.id', $id)
|
|
||||||
->first();
|
|
||||||
|
|
||||||
return collect(['disk' => $node->sum_disk, 'memory' => $node->sum_memory])
|
$stats = $this->getBuilder()->select(
|
||||||
|
$this->getBuilder()->raw('IFNULL(SUM(servers.memory), 0) as sum_memory, IFNULL(SUM(servers.disk), 0) as sum_disk')
|
||||||
|
)->join('servers', 'servers.node_id', '=', 'nodes.id')->where('node_id', $id)->first();
|
||||||
|
|
||||||
|
return collect(['disk' => $stats->sum_disk, 'memory' => $stats->sum_memory])
|
||||||
->mapWithKeys(function ($value, $key) use ($node) {
|
->mapWithKeys(function ($value, $key) use ($node) {
|
||||||
$maxUsage = $node->{$key};
|
$maxUsage = $node->{$key};
|
||||||
if ($node->{$key . '_overallocate'} > 0) {
|
if ($node->{$key . '_overallocate'} > 0) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue