Added cache for home page

Added cache for home page
This commit is contained in:
cp6 2022-03-01 15:59:13 +11:00
parent 077c048dda
commit 07b8cd14c1

View File

@ -5,6 +5,7 @@ namespace App\Http\Controllers;
use App\Models\Pricing;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use App\Process;
use Illuminate\Support\Facades\Session;
@ -28,14 +29,16 @@ class HomeController extends Controller
$p = new Process();
$p->startTimer();
$services_count = DB::table('pricings')
$services_count = Cache::remember('services_count', 1440, function () {
return DB::table('pricings')
->select('service_type', DB::raw('COUNT(*) as amount'))
->groupBy('service_type')
->where('active', '=', 1)
->get();
});
$due_soon = DB::table('pricings as p')
$due_soon = Cache::remember('due_soon', 1440, function () {
return DB::table('pricings as p')
->leftJoin('servers as s', 'p.service_id', '=', 's.id')
->leftJoin('shared_hosting as sh', 'p.service_id', '=', 'sh.id')
->leftJoin('reseller_hosting as r', 'p.service_id', '=', 'r.id')
@ -45,6 +48,7 @@ class HomeController extends Controller
->orderBy('next_due_date', 'ASC')
->limit(6)
->get(['p.*', 's.hostname', 'd.domain', 'd.extension', 'r.main_domain as reseller', 'sh.main_domain', 'ms.name']);
});
//Check for past due date and refresh the due date if so:
@ -64,8 +68,10 @@ class HomeController extends Controller
$count++;
}
Cache::put('due_soon', $due_soon);
$recently_added = DB::table('pricings as p')
$recently_added = Cache::remember('recently_added', 1440, function () {
return DB::table('pricings as p')
->leftJoin('servers as s', 'p.service_id', '=', 's.id')
->leftJoin('shared_hosting as sh', 'p.service_id', '=', 'sh.id')
->leftJoin('reseller_hosting as r', 'p.service_id', '=', 'r.id')
@ -75,10 +81,13 @@ class HomeController extends Controller
->orderBy('created_at', 'DESC')
->limit(6)
->get(['p.*', 's.hostname', 'd.domain', 'd.extension', 'r.main_domain as reseller', 'sh.main_domain', 'ms.name']);
});
$settings = DB::table('settings')
$settings = Cache::remember('settings', 15, function () {
return DB::table('settings')
->where('id', '=', 1)
->get();
});
Session::put('timer_version_footer', $settings[0]->show_versions_footer);
Session::put('show_servers_public', $settings[0]->show_servers_public);
@ -154,8 +163,6 @@ class HomeController extends Controller
'execution_time' => number_format($p->getTimeTaken(), 2)
);
//dd($information);
return view('home', compact('information'));
}
}