Laravel-excel: [BUG] eagerLoad relationships are ignored on queued fromQuery exports

Created on 4 Jan 2019  路  2Comments  路  Source: Maatwebsite/Laravel-Excel

Prerequisites

  • [x] Able to reproduce the behaviour outside of your code, the problem is isolated to Laravel Excel.
  • [x] Checked that your issue isn't already filed.
  • [x] Checked if no PR was submitted that fixes this problem.

Versions

  • PHP version: 7.2
  • Laravel version: 5.7
  • Package version: 3.1

Description

Queued exports that use FromQuery ignores eagerLoaded relationships.

Steps to Reproduce

class UserExport implements FromQuery, WithMapping, ShouldQueue
{
    use Exportable;

    public function query()
    {
        return User::with(['team']);
    }

    public function map($user): array
    {
        return [
            $user->id,
            $user->name,
            $user->team->name,
            $user->team->location,
        ];
    }
}

Expected behavior:

The query should eager load the belongsTo team relationship.

Actual behavior:

The SerializedQuery job only serializes the main query without the eagerLoad property. This results in an N+1 issue anytime a cell is mapped to data from a related table. This could cause a significant performance hit on large queries.

bug help wanted

Most helpful comment

Will be fixed in next release (#2013)

All 2 comments

We indeed don't keep the eager load information. Feel free to PR that addition :)

Will be fixed in next release (#2013)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MLouis picture MLouis  路  21Comments

dlopez picture dlopez  路  23Comments

adnandogar picture adnandogar  路  34Comments

dalholm picture dalholm  路  24Comments

lszanto picture lszanto  路  38Comments