Updated doServicesCount func to be cached

Updated doServicesCount func to be cached
This commit is contained in:
cp6 2022-05-29 17:02:49 +10:00
parent 8e5a1f62c3
commit 025d206618
2 changed files with 32 additions and 26 deletions

View File

@ -19,6 +19,8 @@ class Home extends Model
Cache::forget('due_soon');//Main page due_soon cache Cache::forget('due_soon');//Main page due_soon cache
Cache::forget('recently_added');//Main page recently_added cache Cache::forget('recently_added');//Main page recently_added cache
Cache::forget('all_pricing');//All the pricing Cache::forget('all_pricing');//All the pricing
Cache::forget('services_count_all');
Cache::forget('pricing_breakdown');
} }
public static function servicesCount() public static function servicesCount()
@ -161,36 +163,38 @@ class Home extends Model
public static function doServicesCount($services_count): array public static function doServicesCount($services_count): array
{ {
$servers_count = $domains_count = $shared_count = $reseller_count = $other_count = $seedbox_count = $total_services = 0;
$services_count = json_decode($services_count, true); $services_count = json_decode($services_count, true);
foreach ($services_count as $sc) { return Cache::remember('services_count_all', now()->addWeek(1), function () use ($services_count) {
$total_services += $sc['amount']; $servers_count = $domains_count = $shared_count = $reseller_count = $other_count = $seedbox_count = $total_services = 0;
if ($sc['service_type'] === 1) { foreach ($services_count as $sc) {
$servers_count = $sc['amount']; $total_services += $sc['amount'];
} else if ($sc['service_type'] === 2) { if ($sc['service_type'] === 1) {
$shared_count = $sc['amount']; $servers_count = $sc['amount'];
} else if ($sc['service_type'] === 3) { } else if ($sc['service_type'] === 2) {
$reseller_count = $sc['amount']; $shared_count = $sc['amount'];
} else if ($sc['service_type'] === 4) { } else if ($sc['service_type'] === 3) {
$domains_count = $sc['amount']; $reseller_count = $sc['amount'];
} else if ($sc['service_type'] === 5) { } else if ($sc['service_type'] === 4) {
$other_count = $sc['amount']; $domains_count = $sc['amount'];
} else if ($sc['service_type'] === 6) { } else if ($sc['service_type'] === 5) {
$seedbox_count = $sc['amount']; $other_count = $sc['amount'];
} else if ($sc['service_type'] === 6) {
$seedbox_count = $sc['amount'];
}
} }
}
return array( return array(
'servers' => $servers_count, 'servers' => $servers_count,
'shared' => $shared_count, 'shared' => $shared_count,
'reseller' => $reseller_count, 'reseller' => $reseller_count,
'domains' => $domains_count, 'domains' => $domains_count,
'other' => $other_count, 'other' => $other_count,
'seedbox' => $seedbox_count, 'seedbox' => $seedbox_count,
'total' => $total_services 'total' => $total_services
); );
});
} }

View File

@ -164,6 +164,8 @@ class Server extends Model
Cache::forget('servers_summary');//servers summary cache Cache::forget('servers_summary');//servers summary cache
Cache::forget('public_server_data');//public servers Cache::forget('public_server_data');//public servers
Cache::forget('all_pricing');//All pricing Cache::forget('all_pricing');//All pricing
Cache::forget('services_count_all');
Cache::forget('pricing_breakdown');
} }
public static function serverSpecificCacheForget(string $server_id): void public static function serverSpecificCacheForget(string $server_id): void