Added cache for home page
Added cache for home page
This commit is contained in:
parent
077c048dda
commit
07b8cd14c1
|
@ -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,14 +29,16 @@ 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 () {
|
||||||
|
return DB::table('pricings')
|
||||||
->select('service_type', DB::raw('COUNT(*) as amount'))
|
->select('service_type', DB::raw('COUNT(*) as amount'))
|
||||||
->groupBy('service_type')
|
->groupBy('service_type')
|
||||||
->where('active', '=', 1)
|
->where('active', '=', 1)
|
||||||
->get();
|
->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')
|
||||||
|
@ -45,6 +48,7 @@ class HomeController extends Controller
|
||||||
->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,8 +68,10 @@ 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 () {
|
||||||
|
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')
|
||||||
|
@ -75,10 +81,13 @@ class HomeController extends Controller
|
||||||
->orderBy('created_at', 'DESC')
|
->orderBy('created_at', 'DESC')
|
||||||
->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']);
|
||||||
|
});
|
||||||
|
|
||||||
$settings = DB::table('settings')
|
$settings = Cache::remember('settings', 15, function () {
|
||||||
|
return DB::table('settings')
|
||||||
->where('id', '=', 1)
|
->where('id', '=', 1)
|
||||||
->get();
|
->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'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user