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

Fixing the expired cart command #14532

Closed
wants to merge 1 commit into from

Conversation

mamazu
Copy link
Member

@mamazu mamazu commented Nov 11, 2022

Q A
Branch? 1.13
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Related tickets related to #14481, #14482
License MIT

The problem

Currently when trying to remove a huge amount of expired carts (like 1 million) the process will crash before it even begins. The issue is that in the current implementation findCartsNotModifiedSince returns a list of all carts which kills the memory when trying to execute it.

The solution

Run the find command in a batch and then remove the batch. (The problem is I don't really understand phpspec so someone which more experience with that could maybe help out here.)

I am also using the fact that php has a leaky scope, it's not pretty. But this is the only way to not dispatch more than one SyliusExpiredCartsEvents::POST_REMOVE.

Other considerations

It could even be replaced with a direct delete statement?

@mamazu mamazu requested a review from a team as a code owner November 11, 2022 18:51
@jakubtobiasz
Copy link
Contributor

I was working on it for a while and despite it isn't crashing on the very beginning, the memory seems to leak. Did you try to process ~10k/20k of carts?

@mamazu
Copy link
Member Author

mamazu commented Nov 18, 2022

Yeah, we haven't run the command in a while and gathered over 1 million carts. The proper solution would be to return a result iterator from doctrine and do it like that.

The problem is that this isn't a solution for the Sylius default because this would mean changing the return type of the function. So this duct tape solution must suffice for now.

@vvasiloi
Copy link
Contributor

vvasiloi commented Nov 18, 2022

Just make a new command. 😄
(and deprecate the existing)

@jakubtobiasz
Copy link
Contributor

Iterable isn't working, too. I spent about 1 man day and nothing, after all memory still has been leaking.

@vvasiloi
Copy link
Contributor

Try clearing the entity manager after flushes.

@jakubtobiasz
Copy link
Contributor

jakubtobiasz commented Nov 19, 2022

@vvasiloi I really checked everything, that too 😂.

@mamazu
Copy link
Member Author

mamazu commented Nov 19, 2022

Well that worked for us. flush and clear.

@mamazu
Copy link
Member Author

mamazu commented Nov 19, 2022

Just make a new command. smile (and deprecate the existing)

Or we just take the old command and wire up a different cart remover. But in my opinion we should refactor the command anyways. So that it has a process indicator. Because there is nothing more annoying than having a command with no process indication and only hope that it does something. :D

@mamazu
Copy link
Member Author

mamazu commented Dec 13, 2022

Has been replaced by #14569

@mamazu mamazu closed this Dec 13, 2022
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.

None yet

3 participants