Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Sheets method called twice #3891

Closed
1 task done
oddvalue opened this issue Mar 8, 2023 · 2 comments
Closed
1 task done

[Bug]: Sheets method called twice #3891

oddvalue opened this issue Mar 8, 2023 · 2 comments
Labels

Comments

@oddvalue
Copy link

oddvalue commented Mar 8, 2023

Is the bug applicable and reproducable to the latest version of the package and hasn't it been reported before?

  • Yes, it's still reproducable

What version of Laravel Excel are you using?

3.1.48

What version of Laravel are you using?

9.52.4

What version of PHP are you using?

8.1.12

Describe your issue

When creating a multi-sheet export, the sheets method is called twice. This causes all the queries each sheet to be run twice which can be significant for an export with many sheets and a lof of data.

Could the call in WriterFactory::includesCharts() be handled in such a way that doesn't require a second instantiation of all the sheets?

    private static function includesCharts($export): bool
    {
        if ($export instanceof WithCharts) {
            return true;
        }

        if ($export instanceof WithMultipleSheets) {
            foreach ($export->sheets() as $sheet) {
                if ($sheet instanceof WithCharts) {
                    return true;
                }
            }
        }

        return false;
    }

How can the issue be reproduced?

Create a multi-sheet export and download it.

What should be the expected behaviour?

The method to be called once.

@oddvalue oddvalue added the bug label Mar 8, 2023
@oddvalue oddvalue changed the title [Bug]: [Bug]: Sheets method called twice Mar 8, 2023
@patrickbrouwers
Copy link
Member

That's not possible. Make sure your logic inside sheet can be executed multiple times, either by handling the logic in the constructor or by caching it

@EkoGit-777
Copy link

EkoGit-777 commented Mar 30, 2023

it happens to me too. I realized when I export a report with different total data. the more data the report has, it become slower. then when I print the data on laravel log, I saw my query called twice. only happen when using "WithMultipleSheets"
this is what I used
What version of Laravel Excel are you using?
3.1
What version of Laravel are you using?
10
What version of PHP are you using?
8.1.10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants