Use HPOS feature flag for order cache as well.

This commit is contained in:
Vedanshu Jain 2023-01-24 14:53:29 +05:30
parent 217703a9b6
commit eb2900614c
2 changed files with 6 additions and 45 deletions

View File

@ -4,6 +4,7 @@ namespace Automattic\WooCommerce\Caches;
use Automattic\WooCommerce\Internal\Features\FeaturesController; use Automattic\WooCommerce\Internal\Features\FeaturesController;
use Automattic\WooCommerce\Internal\Traits\AccessiblePrivateMethods; use Automattic\WooCommerce\Internal\Traits\AccessiblePrivateMethods;
use Automattic\WooCommerce\Utilities\OrderUtil;
/** /**
* A class to control the usage of the orders cache. * A class to control the usage of the orders cache.
@ -12,8 +13,6 @@ class OrderCacheController {
use AccessiblePrivateMethods; use AccessiblePrivateMethods;
const FEATURE_NAME = 'orders_cache';
/** /**
* The orders cache to use. * The orders cache to use.
* *
@ -35,56 +34,23 @@ class OrderCacheController {
*/ */
private $orders_cache_usage_backup = null; private $orders_cache_usage_backup = null;
/**
* Creates a new instance of the class.
*/
public function __construct() {
self::add_action( FeaturesController::FEATURE_ENABLED_CHANGED_ACTION, array( $this, 'handle_feature_enable_changed' ), 10, 2 );
}
/** /**
* Class initialization, invoked by the DI container. * Class initialization, invoked by the DI container.
* *
* @internal * @internal
* @param OrderCache $order_cache The order cache engine to use. * @param OrderCache $order_cache The order cache engine to use.
* @param FeaturesController $features_controller The features controller to use.
*/ */
final public function init( OrderCache $order_cache, FeaturesController $features_controller ) { final public function init( OrderCache $order_cache ) {
$this->order_cache = $order_cache; $this->order_cache = $order_cache;
$this->features_controller = $features_controller;
} }
/** /**
* Handler for the feature enable changed action, when the orders cache is enabled or disabled it flushes it. * Whether order cache usage is enabled. Currently, linked to custom orders' table usage.
* *
* @param string $feature_id The id of the feature whose enable status changed. * @return bool True if the order cache is enabled.
* @param bool $enabled Whether the feature has been enabled or disabled.
* @return void
*/
private function handle_feature_enable_changed( string $feature_id, bool $enabled ): void {
if ( self::FEATURE_NAME === $feature_id ) {
$this->order_cache->flush();
}
}
/**
* Set the value of the order cache usage setting.
*
* @param bool $enable True if the order cache should be used, false if not.
* @throws \Exception Attempt to enable the orders cache usage while it's temporarily disabled.
*/
public function set_orders_cache_usage( bool $enable ): void {
$this->features_controller->change_feature_enable( $enable );
$this->orders_cache_usage_backup = null;
}
/**
* Get the value of the order cache usage setting.
*
* @return bool True if order cache usage setting is currently enabled, false if not.
*/ */
public function orders_cache_usage_is_enabled(): bool { public function orders_cache_usage_is_enabled(): bool {
return ! $this->orders_cache_usage_is_temporarly_disabled() && $this->features_controller->feature_is_enabled( self::FEATURE_NAME ); return OrderUtil::custom_orders_table_usage_is_enabled();
} }
/** /**

View File

@ -111,11 +111,6 @@ class FeaturesController {
'description' => __( 'Enable the high performance order storage feature.', 'woocommerce' ), 'description' => __( 'Enable the high performance order storage feature.', 'woocommerce' ),
'is_experimental' => true, 'is_experimental' => true,
), ),
OrderCacheController::FEATURE_NAME => array(
'name' => __( 'Orders cache', 'woocommerce' ),
'description' => __( 'Enable the usage of a cache for shop orders', 'woocommerce' ),
'is_experimental' => true,
),
); );
$this->legacy_feature_ids = array( 'analytics', 'new_navigation', 'new_product_management' ); $this->legacy_feature_ids = array( 'analytics', 'new_navigation', 'new_product_management' );