Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.2] Pagination optimize #14188

Merged
merged 3 commits into from
Jul 1, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Make paginate query to get data only if there are any results
mnabialek committed Jun 30, 2016
commit f377dc90ab6c0f2d3baf8faf30411d7266d360b2
6 changes: 3 additions & 3 deletions src/Illuminate/Database/Eloquent/Builder.php
Original file line number Diff line number Diff line change
@@ -486,12 +486,12 @@ public function paginate($perPage = null, $columns = ['*'], $pageName = 'page',

$total = $query->getCountForPagination();

$this->forPage(
$results = $total ? $this->forPage(
$page = $page ?: Paginator::resolveCurrentPage($pageName),
$perPage = $perPage ?: $this->model->getPerPage()
);
)->get($columns) : [];

return new LengthAwarePaginator($this->get($columns), $total, $perPage, $page, [
return new LengthAwarePaginator($results, $total, $perPage, $page, [
'path' => Paginator::resolveCurrentPath(),
'pageName' => $pageName,
]);
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Query/Builder.php
Original file line number Diff line number Diff line change
@@ -1598,7 +1598,7 @@ public function paginate($perPage = 15, $columns = ['*'], $pageName = 'page', $p

$total = $this->getCountForPagination($columns);

$results = $this->forPage($page, $perPage)->get($columns);
$results = $total ? $this->forPage($page, $perPage)->get($columns) : [];

return new LengthAwarePaginator($results, $total, $perPage, $page, [
'path' => Paginator::resolveCurrentPath(),