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,10 +163,10 @@ 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);
return Cache::remember('services_count_all', now()->addWeek(1), function () use ($services_count) {
$servers_count = $domains_count = $shared_count = $reseller_count = $other_count = $seedbox_count = $total_services = 0;
foreach ($services_count as $sc) { foreach ($services_count as $sc) {
$total_services += $sc['amount']; $total_services += $sc['amount'];
if ($sc['service_type'] === 1) { if ($sc['service_type'] === 1) {
@ -191,6 +193,8 @@ class Home extends Model
'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