Merge pull request #434 from Tobiletsmc/development
Increase Controlpanel performance with fetch servers with product to reduce SQL-Queries
This commit is contained in:
commit
3d1cf9116b
1 changed files with 9 additions and 4 deletions
|
@ -196,7 +196,7 @@ class User extends Authenticatable implements MustVerifyEmail
|
|||
*/
|
||||
public function unSuspend()
|
||||
{
|
||||
foreach ($this->servers as $server) {
|
||||
foreach ($this->getServersWithProduct() as $server) {
|
||||
if ($this->credits >= $server->product->getHourlyPrice()) {
|
||||
$server->unSuspend();
|
||||
}
|
||||
|
@ -233,14 +233,19 @@ class User extends Authenticatable implements MustVerifyEmail
|
|||
* @return string
|
||||
*/
|
||||
public function creditUsage()
|
||||
{
|
||||
{
|
||||
$usage = 0;
|
||||
|
||||
foreach ($this->Servers as $server) {
|
||||
foreach ($this->getServersWithProduct() as $server) {
|
||||
$usage += $server->product->price;
|
||||
}
|
||||
|
||||
return number_format($usage, 2, '.', '');
|
||||
}
|
||||
|
||||
private function getServersWithProduct() {
|
||||
return $this->servers()
|
||||
->with('product')
|
||||
->get();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue