refactor: count on the query, not collection
This commit introduces a short performance boost by counting the records in the query itself, instead of doing that in the collection Laravel returns. Signed-off-by: miguel456 <me@nogueira.codes>
This commit is contained in:
parent
839219ae4b
commit
f43ff4e9a0
@ -32,9 +32,9 @@ class DashboardController extends Controller
|
|||||||
|
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
$totalPeerReview = Application::where('applicationStatus', 'STAGE_PEERAPPROVAL')->get()->count();
|
$totalPeerReview = Application::where('applicationStatus', 'STAGE_PEERAPPROVAL')->count();
|
||||||
$totalNewApplications = Application::where('applicationStatus', 'STAGE_SUBMITTED')->get()->count();
|
$totalNewApplications = Application::where('applicationStatus', 'STAGE_SUBMITTED')->count();
|
||||||
$totalDenied = Application::where('applicationStatus', 'DENIED')->get()->count();
|
$totalDenied = Application::where('applicationStatus', 'DENIED')->count();
|
||||||
$vacancies = Vacancy::where('vacancyStatus', '<>', 'CLOSED')->get();
|
$vacancies = Vacancy::where('vacancyStatus', '<>', 'CLOSED')->get();
|
||||||
|
|
||||||
$totalDeniedSingle = Application::where([
|
$totalDeniedSingle = Application::where([
|
||||||
@ -50,7 +50,7 @@ class DashboardController extends Controller
|
|||||||
return view('dashboard.dashboard')
|
return view('dashboard.dashboard')
|
||||||
->with([
|
->with([
|
||||||
'vacancies' => $vacancies,
|
'vacancies' => $vacancies,
|
||||||
'totalUserCount' => User::all()->count(),
|
'totalUserCount' => User::count(),
|
||||||
'totalDenied' => $totalDenied,
|
'totalDenied' => $totalDenied,
|
||||||
'totalPeerReview' => $totalPeerReview,
|
'totalPeerReview' => $totalPeerReview,
|
||||||
'totalNewApplications' => $totalNewApplications,
|
'totalNewApplications' => $totalNewApplications,
|
||||||
|
@ -76,7 +76,7 @@ class UserController extends Controller
|
|||||||
->with([
|
->with([
|
||||||
'users' => User::with('roles')->paginate('6'),
|
'users' => User::with('roles')->paginate('6'),
|
||||||
'numUsers' => count(User::all()),
|
'numUsers' => count(User::all()),
|
||||||
'bannedUserCount' => Ban::all()->count(),
|
'bannedUserCount' => Ban::count(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,7 +106,7 @@ class UserController extends Controller
|
|||||||
->with([
|
->with([
|
||||||
'users' => $matchingUsers,
|
'users' => $matchingUsers,
|
||||||
'numUsers' => count(User::all()),
|
'numUsers' => count(User::all()),
|
||||||
'bannedUserCount' => Ban::all()->count(),
|
'bannedUserCount' => Ban::count(),
|
||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
$request->session()->flash('error', __('Your search term did not return any results.'));
|
$request->session()->flash('error', __('Your search term did not return any results.'));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user