From 248e8ffa81e1a3131477185263fe77aad0316fd4 Mon Sep 17 00:00:00 2001 From: Vedanshu Jain Date: Mon, 10 Oct 2022 13:45:18 +0530 Subject: [PATCH] Revert "Revert "[COT] Add the orders cache" (#34992)" This reverts commit 0b5d7ab9ad4ef09fc0ef47c5deddfe2aa4f7e5c3. --- plugins/woocommerce/changelog/add-order_cache | 4 + .../includes/abstracts/abstract-wc-order.php | 7 + .../admin/class-wc-admin-settings.php | 3 + .../includes/class-wc-order-factory.php | 45 +++++- plugins/woocommerce/src/Caches/OrderCache.php | 44 ++++++ .../src/Caches/OrderCacheController.php | 121 ++++++++++++++++ .../woocommerce/src/Caching/ObjectCache.php | 74 ++++++++-- .../Orders/CustomOrdersTableController.php | 44 +++++- .../DataStores/Orders/DataSynchronizer.php | 6 + .../COTMigrationServiceProvider.php | 3 +- .../OrdersDataStoreServiceProvider.php | 7 + .../Internal/Features/FeaturesController.php | 5 + .../woocommerce/src/Utilities/OrderUtil.php | 11 ++ .../class-wc-rest-orders-controller-tests.php | 7 +- .../tests/php/src/Caching/ObjectCacheTest.php | 131 ++++++++++++++---- 15 files changed, 460 insertions(+), 52 deletions(-) create mode 100644 plugins/woocommerce/changelog/add-order_cache create mode 100644 plugins/woocommerce/src/Caches/OrderCache.php create mode 100644 plugins/woocommerce/src/Caches/OrderCacheController.php diff --git a/plugins/woocommerce/changelog/add-order_cache b/plugins/woocommerce/changelog/add-order_cache new file mode 100644 index 00000000000..1b800aff214 --- /dev/null +++ b/plugins/woocommerce/changelog/add-order_cache @@ -0,0 +1,4 @@ +Significance: minor +Type: add + +Add a cache for orders, to use when custom order tables are enabled diff --git a/plugins/woocommerce/includes/abstracts/abstract-wc-order.php b/plugins/woocommerce/includes/abstracts/abstract-wc-order.php index 78932ad68bc..bebe53ada46 100644 --- a/plugins/woocommerce/includes/abstracts/abstract-wc-order.php +++ b/plugins/woocommerce/includes/abstracts/abstract-wc-order.php @@ -10,9 +10,11 @@ * @package WooCommerce\Classes */ +use Automattic\WooCommerce\Caches\OrderCache; use Automattic\WooCommerce\Proxies\LegacyProxy; use Automattic\WooCommerce\Utilities\ArrayUtil; use Automattic\WooCommerce\Utilities\NumberUtil; +use Automattic\WooCommerce\Utilities\OrderUtil; defined( 'ABSPATH' ) || exit; @@ -203,6 +205,11 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order { $this->save_items(); + if ( OrderUtil::orders_cache_usage_is_enabled() ) { + $order_cache = wc_get_container()->get( OrderCache::class ); + $order_cache->update_if_cached( $this ); + } + /** * Trigger action after saving to the DB. * diff --git a/plugins/woocommerce/includes/admin/class-wc-admin-settings.php b/plugins/woocommerce/includes/admin/class-wc-admin-settings.php index 477ae41ea61..2958d949806 100644 --- a/plugins/woocommerce/includes/admin/class-wc-admin-settings.php +++ b/plugins/woocommerce/includes/admin/class-wc-admin-settings.php @@ -488,6 +488,8 @@ if ( ! class_exists( 'WC_Admin_Settings', false ) ) : $visibility_class[] = 'show_options_if_checked'; } + $must_disable = ArrayUtil::get_value_or_default( $value, 'disabled', false ); + if ( ! isset( $value['checkboxgroup'] ) || 'start' === $value['checkboxgroup'] ) { $has_tooltip = isset( $value['tooltip'] ) && '' !== $value['tooltip']; $tooltip_container_class = $has_tooltip ? 'with-tooltip' : ''; @@ -515,6 +517,7 @@ if ( ! class_exists( 'WC_Admin_Settings', false ) ) : ?>