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