diff --git a/plugins/woocommerce/changelog/perf-use-in-operator b/plugins/woocommerce/changelog/perf-use-in-operator new file mode 100644 index 00000000000..3ec963c5b89 --- /dev/null +++ b/plugins/woocommerce/changelog/perf-use-in-operator @@ -0,0 +1,4 @@ +Significance: patch +Type: performance + +Refactor Country Specs to use 'in' operator diff --git a/plugins/woocommerce/src/Admin/Features/ShippingPartnerSuggestions/DefaultShippingPartners.php b/plugins/woocommerce/src/Admin/Features/ShippingPartnerSuggestions/DefaultShippingPartners.php index 34cffa99152..066838193f8 100644 --- a/plugins/woocommerce/src/Admin/Features/ShippingPartnerSuggestions/DefaultShippingPartners.php +++ b/plugins/woocommerce/src/Admin/Features/ShippingPartnerSuggestions/DefaultShippingPartners.php @@ -316,19 +316,10 @@ class DefaultShippingPartners { * @return object Rules to match. */ public static function get_rules_for_countries( $countries ) { - $rules = array(); - - foreach ( $countries as $country ) { - $rules[] = (object) array( - 'type' => 'base_location_country', - 'value' => $country, - 'operation' => '=', - ); - } - return (object) array( - 'type' => 'or', - 'operands' => $rules, + 'type' => 'base_location_country', + 'operation' => 'in', + 'value' => $countries, ); } } diff --git a/plugins/woocommerce/src/Internal/Admin/RemoteFreeExtensions/DefaultFreeExtensions.php b/plugins/woocommerce/src/Internal/Admin/RemoteFreeExtensions/DefaultFreeExtensions.php index 5e1faf15127..03accf1df58 100644 --- a/plugins/woocommerce/src/Internal/Admin/RemoteFreeExtensions/DefaultFreeExtensions.php +++ b/plugins/woocommerce/src/Internal/Admin/RemoteFreeExtensions/DefaultFreeExtensions.php @@ -185,204 +185,49 @@ class DefaultFreeExtensions { ), 'is_visible' => array( array( - 'type' => 'or', - 'operands' => array( - array( - 'type' => 'base_location_country', - 'value' => 'US', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'PR', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'AU', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'CA', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'DE', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'ES', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'FR', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'GB', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'IE', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'IT', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'NZ', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'AT', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'BE', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'NL', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'PL', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'PT', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'CH', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'HK', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'SG', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'CY', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'DK', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'EE', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'FI', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'GR', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'LU', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'LT', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'LV', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'NO', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'MT', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'SI', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'SK', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'BG', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'CZ', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'HR', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'HU', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'RO', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'SE', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'JP', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'AE', - 'operation' => '=', - ), + 'type' => 'base_location_country', + 'value' => array( + 'US', + 'PR', + 'AU', + 'CA', + 'DE', + 'ES', + 'FR', + 'GB', + 'IE', + 'IT', + 'NZ', + 'AT', + 'BE', + 'NL', + 'PL', + 'PT', + 'CH', + 'HK', + 'SG', + 'CY', + 'DK', + 'EE', + 'FI', + 'GR', + 'LU', + 'LT', + 'LV', + 'NO', + 'MT', + 'SI', + 'SK', + 'BG', + 'CZ', + 'HR', + 'HU', + 'RO', + 'SE', + 'JP', + 'AE', ), + 'operation' => 'in', ), DefaultPaymentGateways::get_rules_for_cbd( false ), ), @@ -578,209 +423,50 @@ class DefaultFreeExtensions { 'manage_url' => 'admin.php?page=tiktok', 'is_visible' => array( array( - 'type' => 'or', - 'operands' => array( - array( - 'type' => 'base_location_country', - 'value' => 'US', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'CA', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'MX', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'AT', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'BE', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'CZ', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'DK', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'FI', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'FR', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'DE', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'GR', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'HU', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'IE', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'IT', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'NL', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'PL', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'PT', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'RO', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'ES', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'SE', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'GB', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'CH', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'NO', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'AU', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'NZ', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'SG', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'MY', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'PH', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'ID', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'VN', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'TH', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'KR', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'IL', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'AE', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'RU', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'UA', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'TR', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'SA', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'BR', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'JP', - 'operation' => '=', - ), + 'type' => 'base_location_country', + 'value' => array( + 'US', + 'CA', + 'MX', + 'AT', + 'BE', + 'CZ', + 'DK', + 'FI', + 'FR', + 'DE', + 'GR', + 'HU', + 'IE', + 'IT', + 'NL', + 'PL', + 'PT', + 'RO', + 'ES', + 'SE', + 'GB', + 'CH', + 'NO', + 'AU', + 'NZ', + 'SG', + 'MY', + 'PH', + 'ID', + 'VN', + 'TH', + 'KR', + 'IL', + 'AE', + 'RU', + 'UA', + 'TR', + 'SA', + 'BR', + 'JP', ), + 'operation' => 'in', ), ), 'is_built_by_wc' => false, @@ -997,63 +683,20 @@ class DefaultFreeExtensions { */ private static function get_rules_for_wcservices_tax_countries() { return array( - 'type' => 'or', - 'operands' => array( - array( - 'type' => 'base_location_country', - 'value' => 'US', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'FR', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'GB', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'DE', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'CA', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'AU', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'GR', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'BE', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'PT', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'DK', - 'operation' => '=', - ), - array( - 'type' => 'base_location_country', - 'value' => 'SE', - 'operation' => '=', - ), + 'type' => 'base_location_country', + 'operation' => 'in', + 'value' => array( + 'US', + 'FR', + 'GB', + 'DE', + 'CA', + 'AU', + 'GR', + 'BE', + 'PT', + 'DK', + 'SE', ), ); }