Merge pull request #434 from Tobiletsmc/development

Increase Controlpanel performance with fetch servers with product to reduce SQL-Queries
This commit is contained in:
Dennis 2022-06-07 16:55:11 +02:00 committed by GitHub
commit 3d1cf9116b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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();
}
/**