Laravel-excel: [PROPOSAL] Allow exports with Lazy Collections

Created on 29 Aug 2019  路  9Comments  路  Source: Maatwebsite/Laravel-Excel

Prerequisites

Laravel 6.0

Versions

  • PHP version: 7.2
  • Laravel version: 6.0
  • Package version:

Description

If I understand Lazy Collections correctly, it cold be used to reduce the memory usage when exporting large datasets with laravel-excel.

Example

Need more information to prepare an example.

Additional Information

I am not entirely sure how laravel-excel works under the hood, so I don't have a clue if this is a valid proposal - it's more of an idea.

proposal

Most helpful comment

You used to be able to use a LazyCollection for queued exports, but since this commit, it's required to use a Collection. Is there a reason this method was changed to force users to use a Collection?

If we make the exportCollection method return Enumerable, that way you can pass a Collection or a LazyCollection.

All 9 comments

I am not entirely sure how laravel-excel works under the hood, so I don't have a clue if this is a valid proposal - it's more of an idea.

In that case, you may check the Architecture documentation, which may clarify some of the concepts of Laravel Excel to you.

It would only be interesting if we could turn PhpSpreadsheets reading into a generator, which could be possible because it has an iterator. I'll leave this open as a future improvement. PR's are welcomed.

+1

@patrickbrouwers could you give me a hint on where I need to look at/start to implement the generator for PHPSpreadsheets?

This was actually already possible when using the FromCollection concern:

public function collection() {
    return new LazyCollection();

    // or
    return User::query()->cursor();
}

You used to be able to use a LazyCollection for queued exports, but since this commit, it's required to use a Collection. Is there a reason this method was changed to force users to use a Collection?

If we make the exportCollection method return Enumerable, that way you can pass a Collection or a LazyCollection.

Any Updates ? on lazy collections for laravel excel 3.1 or there are any other solutions for this big data export. Meanwhile shoulQueue with fromQuery concerns still get memory exceptions for big data export

This was actually already possible when using the FromCollection concern:

public function collection() {
    return new LazyCollection();

    // or
    return User::query()->cursor();
}

Haven't seen any PR's, so no updates.

Was this page helpful?
0 / 5 - 0 ratings