Download the PHP package itsimiro/laravel-chunk-cursor without Composer
On this page you can find all versions of the php package itsimiro/laravel-chunk-cursor. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download itsimiro/laravel-chunk-cursor
More information about itsimiro/laravel-chunk-cursor
Files in itsimiro/laravel-chunk-cursor
Package laravel-chunk-cursor
Short Description Laravel Eloquent cursor with eager loading and chunking
License MIT
Homepage https://github.com/miroslaws8/laravel-chunk-cursor
Informations about the package laravel-chunk-cursor
Laravel Chunk Cursor
This package provides a functionality that adds a chunkCursor
to the Illuminate\Database\Eloquent\Builder
class. This allows you to fetch large datasets in chunks using a cursor, reducing memory usage and use eager loading!
Why use that?
The eloquent method of the cursor builder does not support eager load relations, but with this package you will be able to use with()
and load()
as before with all the charms of cursor().
Installation
You can install the package via composer:
Usage
Here's an example of how you can use the chunkCursor macro:
With cursor()
:
With chunkCursor()
:
In this example, the users are fetched in chunks of 50. You can adjust the chunk size to suit your needs.
Compare the execution time
Let's make a comparison without eager loading, and we'll see that chunkCursor is 2 times faster.
With cursor()
:
With chunkCursor()
:
As you can see, if we add relationship loading, cursor will work even slower, because it will have to make a new request to the database every time to get data.
Testing
To run the tests for this package, use the following command: