Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Added 'chunk' method.
Added 'chunk' method to query builder and Eloquent for doing work on
large result sets.
- Loading branch information
|
@@ -136,6 +136,30 @@ public function pluck($column) |
|
|
if ($result) return $result->{$column}; |
|
|
} |
|
|
|
|
|
/** |
|
|
* Chunk the results of the query. |
|
|
* |
|
|
* @param int $count |
|
|
* @param callable $callback |
|
|
* @return void |
|
|
*/ |
|
|
public function chunk($count, $callback) |
|
|
{ |
|
|
$results = $this->forPage($page = 1, $count)->get(); |
|
|
|
|
|
while (count($results) > 0) |
|
|
{ |
|
|
// On each chunk result set, we will pass them to the callback and then let the |
|
|
// developer take care of everything within the callback, which allows us to |
|
|
// keep the memory low for spinning through large result sets for working. |
|
|
call_user_func($callback, $results); |
|
|
|
|
|
$page++; |
|
|
|
|
|
$results = $this->forPage($page, $count)->get(); |
|
|
} |
|
|
} |
|
|
|
|
|
/** |
|
|
* Get an array with the values of a given column. |
|
|
* |
|
|
|
@@ -1074,6 +1074,30 @@ protected function getCacheCallback($columns) |
|
|
return function() use ($me, $columns) { return $me->getFresh($columns); }; |
|
|
} |
|
|
|
|
|
/** |
|
|
* Chunk the results of the query. |
|
|
* |
|
|
* @param int $count |
|
|
* @param callable $callback |
|
|
* @return void |
|
|
*/ |
|
|
public function chunk($count, $callback) |
|
|
{ |
|
|
$results = $this->forPage($page = 1, $count)->get(); |
|
|
|
|
|
while (count($results) > 0) |
|
|
{ |
|
|
// On each chunk result set, we will pass them to the callback and then let the |
|
|
// developer take care of everything within the callback, which allows us to |
|
|
// keep the memory low for spinning through large result sets for working. |
|
|
call_user_func($callback, $results); |
|
|
|
|
|
$page++; |
|
|
|
|
|
$results = $this->forPage($page, $count)->get(); |
|
|
} |
|
|
} |
|
|
|
|
|
/** |
|
|
* Get an array with the values of a given column. |
|
|
* |
|
|
|
@@ -34,6 +34,7 @@ |
|
|
{"message": "Allow connection to be configurable when using Redis based sessions.", "backport": null}, |
|
|
{"message": "Allow passing DateTime objects to Queue::later.", "backport": null}, |
|
|
{"message": "Added Queue::bulk method for pushing several jobs out at once.", "backport": null}, |
|
|
{"message": "Added 'dates' property to Eloquent model for convenient setting of date columns.", "backport": null} |
|
|
{"message": "Added 'dates' property to Eloquent model for convenient setting of date columns.", "backport": null}, |
|
|
{"message": "Added 'chunk' method to query builder and Eloquent for doing work on large result sets.", "backport": null} |
|
|
] |
|
|
}
|
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session.
You signed out in another tab or window. Reload to refresh your session.
This comment has been minimized.
11d3e98
I think the Eloquent method is not necessary, as it will be routed to
Query\Builder
anyway though__call
?