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
|
@ -196,7 +196,7 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||||
*/
|
*/
|
||||||
public function unSuspend()
|
public function unSuspend()
|
||||||
{
|
{
|
||||||
foreach ($this->servers as $server) {
|
foreach ($this->getServersWithProduct() as $server) {
|
||||||
if ($this->credits >= $server->product->getHourlyPrice()) {
|
if ($this->credits >= $server->product->getHourlyPrice()) {
|
||||||
$server->unSuspend();
|
$server->unSuspend();
|
||||||
}
|
}
|
||||||
|
@ -233,14 +233,19 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function creditUsage()
|
public function creditUsage()
|
||||||
{
|
{
|
||||||
$usage = 0;
|
$usage = 0;
|
||||||
|
foreach ($this->getServersWithProduct() as $server) {
|
||||||
foreach ($this->Servers as $server) {
|
|
||||||
$usage += $server->product->price;
|
$usage += $server->product->price;
|
||||||
}
|
}
|
||||||
|
|
||||||
return number_format($usage, 2, '.', '');
|
return number_format($usage, 2, '.', '');
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getServersWithProduct() {
|
||||||
|
return $this->servers()
|
||||||
|
->with('product')
|
||||||
|
->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue