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

Feat flush view data #451

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Feat flush view data #451

wants to merge 2 commits into from

Conversation

viest
Copy link

@viest viest commented Feb 25, 2022

The view data keeps appending causing memory to increase.

For example.

There is a timed task to send emails, I send 100 emails with different data, the view data length will be 100, the data volume is large but the memory is relatively small, it can easily lead to killed.

Add a method to clean up view data, users can clean up unnecessary data by themselves to protect memory.

for ($index = 0; $index < 100; $index++) {
    /* @var Factory $viewFactor */
    $viewFactor = Mail::getViewFactory();

    $view = $viewFactor->make('email.view', [
        // big data......
    ]);

    // get html
    $data = $view->render();

    /* @var CompilerEngine $viewEngine */
    $viewEngine = $view->getEngine();
    $viewEngine->flushViewData();

    // send mail via raw data
    // ......
}

The view data keeps appending causing memory to increase.

For example.

There is a timed task to send emails, I send 100 emails with different data, the view data length will be 100, the data volume is large but the memory is relatively small, it can easily lead to killed.

```php
        for ($index = 0; $index < 100; $index++) {
            /* @var Factory $viewFactor */
            $viewFactor = Mail::getViewFactory();

            $view = $viewFactor->make('email.view', [
                // ......
            ]);

            // get html
            $data = $view->render();

            /* @var CompilerEngine $viewEngine */
            $viewEngine = $view->getEngine();
            $viewEngine->flushViewData();

            // send mail via raw data
            // ......
        }
```
@freekmurze
Copy link
Collaborator

Could you also document this function in the readme?

@viest
Copy link
Author

viest commented Feb 28, 2022

I described what the function does through comments, does this meet your requirements?

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

Successfully merging this pull request may close these issues.

3 participants