Permalink
Browse files

Added 'chunk' method.

Added 'chunk' method to query builder and Eloquent for doing work on
large result sets.
  • Loading branch information...
taylorotwell committed Sep 19, 2013
1 parent 9857193 commit 11d3e9850dc6139850d5e81c71067ae2d7a894d9
@@ -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}
]
}

1 comment on commit 11d3e98

@JoostK

This comment has been minimized.

Contributor

JoostK commented on 11d3e98 Sep 20, 2013

I think the Eloquent method is not necessary, as it will be routed to Query\Builder anyway though __call?

Please sign in to comment.