Description
Summary
Preconditions (*)
- Products added to cart
Steps to reproduce (*)
- Enter PDP with profiler enabled
- Quote is not expired and the quote is fully loaded to check this, performance suffers
Expected result (*)
persistent_quote
observer does not load the quote before it's absolutely necessary
Actual result (*)
persistent_quote
is loading the full quote with expensiveassignProducts
function call
Magento_Persistent
adds controller_action_predispatch
event persistent_quote
observer. On non-cart, non-checkout pages(e.g. PDP) it's loading quote and it impacts the TTFB significantly. Due to the observer's private function declarations, overriding the logic inside the observer class requires developers to add class preference or patch the observer class directly. There is no "ok" way to implement workaround for this.
Both of these calls could be simplified by checking the quote table data directly. The business logic will still be satisfied. If the quote has to be expired, then the quote probably needs to be still loaded fully.
Examples
class QuoteResourceWrapper
{
public function __construct(
private readonly ResourceConnection $resourceConnection
) {
}
public function isActive(?int $quoteId): bool
{
if (empty($quoteId)) {
return false;
}
$table = $this->resourceConnection->getTableName('quote');
$connection = $this->resourceConnection->getConnection();
$select = $connection->select()
->from($table, 'is_active')
->where('entity_id = ?', $quoteId);
return $connection->fetchOne($select) == true;
}
public function isPersistent(?int $quoteId): bool
{
if (empty($quoteId)) {
return false;
}
$table = $this->resourceConnection->getTableName('quote');
$connection = $this->resourceConnection->getConnection();
$select = $connection->select()
->from($table, 'is_persistent')
->where('entity_id = ?', $quoteId);
return $connection->fetchOne($select) == true;
}
}
Proposed solution
Do not load quote fully if not needed.
I have prepared a sample class that could be used as a wrapper for getting the required data instead, see Examples
Release note
No response
Triage and priority
- Severity: S0 - Affects critical data or functionality and leaves users without workaround.
- Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
- Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
- Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
- Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status