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

Added cache to "order status" labels in Mage_Sales_Model_Order_Config #3223

Merged

Conversation

elidrissidev
Copy link
Member

@elidrissidev elidrissidev commented Apr 27, 2023

Description (*)

A small performance improvement when retrieving Order status labels (either from Mage_Sales_Model_Order or Mage_Sales_Model_Order_Status_History) which is now going to check an array that serves as a cache first before loading them from the database if they don't exist.

Before, this resulted in a database query per every invocation, which resulted in many duplicate queries (found it by DebugBar extension I'm creating ;) ).

Manual testing scenarios

<?php

require 'app/Mage.php';

Mage::app();

Mage::getSingleton('sales/order_config')->getStatusLabel('pending');
// performs a db request and returns "Pending"

Mage::getSingleton('sales/order_config')->getStatusLabel('pending');
// returns immediately "Pending"

Mage::app()->setCurrentStore(2);

Mage::getSingleton('sales/order_config')->getStatusLabel('pending');
// performs a db request and returns "En attente" assuming store has different label

Questions or comments

The key consists of the store id as well to prevent issues with emulation when labels are localized.

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All automated tests passed successfully (all builds are green)
  • Add yourself to contributors list

@elidrissidev elidrissidev added the performance Performance related label Apr 27, 2023
@github-actions github-actions bot added the Component: Sales Relates to Mage_Sales label Apr 27, 2023
Co-authored-by: Fabrizio Balliano <fabrizio.balliano@gmail.com>
@fballiano fballiano merged commit 6b683d7 into OpenMage:main May 4, 2023
@fballiano fballiano changed the title Cache Order status labels in an array Added cache to "order status" labels in Mage_Sales_Model_Order_Config May 4, 2023
@elidrissidev elidrissidev deleted the perf/cache-order-status-labels branch May 4, 2023 09:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Sales Relates to Mage_Sales performance Performance related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants