[Backport] Prevent running SQL query on every item in the database when the quote is empty #16898
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Original Pull Request
#16675
Description
During custom development on Magento, we needed the ability to have a quote be created and loaded into the session with no items. We started noticing performance issues throughout ajax banner loads and checkout cart loads after this change. After further inspection, we noticed that a call to
\Magento\Quote\Model\ResourceModel\Quote\Item\Collection::removeItemsWithAbsentProducts
resulted in a query on thecatalog_product_entity
table that performed a table scan across all 1.3 million products in the database, simply because no filter was being applied. The requested change simply is a check if there are any product ids to filter before attempting to filter. While this may not affect any stand-alone magento installations, it has no negative effect and if any other developer seeks to implement the capability of loading empty quotes into the session, this will alleviate potential performance issues.Contribution checklist