Refactor Country Specs to use in operator (#51162)

* Refactor Country Specs to use in operator

* Add changelog

* Refactor shipping specs
This commit is contained in:
Chi-Hsuan Huang 2024-09-06 15:45:49 +08:00 committed by GitHub
parent b4f1062783
commit 19661e3317
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 106 additions and 468 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: performance
Refactor Country Specs to use 'in' operator

View File

@ -316,19 +316,10 @@ class DefaultShippingPartners {
* @return object Rules to match. * @return object Rules to match.
*/ */
public static function get_rules_for_countries( $countries ) { 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( return (object) array(
'type' => 'or', 'type' => 'base_location_country',
'operands' => $rules, 'operation' => 'in',
'value' => $countries,
); );
} }
} }

View File

@ -185,204 +185,49 @@ class DefaultFreeExtensions {
), ),
'is_visible' => array( 'is_visible' => array(
array( array(
'type' => 'or', 'type' => 'base_location_country',
'operands' => array( 'value' => array(
array( 'US',
'type' => 'base_location_country', 'PR',
'value' => 'US', 'AU',
'operation' => '=', 'CA',
), 'DE',
array( 'ES',
'type' => 'base_location_country', 'FR',
'value' => 'PR', 'GB',
'operation' => '=', 'IE',
), 'IT',
array( 'NZ',
'type' => 'base_location_country', 'AT',
'value' => 'AU', 'BE',
'operation' => '=', 'NL',
), 'PL',
array( 'PT',
'type' => 'base_location_country', 'CH',
'value' => 'CA', 'HK',
'operation' => '=', 'SG',
), 'CY',
array( 'DK',
'type' => 'base_location_country', 'EE',
'value' => 'DE', 'FI',
'operation' => '=', 'GR',
), 'LU',
array( 'LT',
'type' => 'base_location_country', 'LV',
'value' => 'ES', 'NO',
'operation' => '=', 'MT',
), 'SI',
array( 'SK',
'type' => 'base_location_country', 'BG',
'value' => 'FR', 'CZ',
'operation' => '=', 'HR',
), 'HU',
array( 'RO',
'type' => 'base_location_country', 'SE',
'value' => 'GB', 'JP',
'operation' => '=', 'AE',
),
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' => '=',
),
), ),
'operation' => 'in',
), ),
DefaultPaymentGateways::get_rules_for_cbd( false ), DefaultPaymentGateways::get_rules_for_cbd( false ),
), ),
@ -578,209 +423,50 @@ class DefaultFreeExtensions {
'manage_url' => 'admin.php?page=tiktok', 'manage_url' => 'admin.php?page=tiktok',
'is_visible' => array( 'is_visible' => array(
array( array(
'type' => 'or', 'type' => 'base_location_country',
'operands' => array( 'value' => array(
array( 'US',
'type' => 'base_location_country', 'CA',
'value' => 'US', 'MX',
'operation' => '=', 'AT',
), 'BE',
array( 'CZ',
'type' => 'base_location_country', 'DK',
'value' => 'CA', 'FI',
'operation' => '=', 'FR',
), 'DE',
array( 'GR',
'type' => 'base_location_country', 'HU',
'value' => 'MX', 'IE',
'operation' => '=', 'IT',
), 'NL',
array( 'PL',
'type' => 'base_location_country', 'PT',
'value' => 'AT', 'RO',
'operation' => '=', 'ES',
), 'SE',
array( 'GB',
'type' => 'base_location_country', 'CH',
'value' => 'BE', 'NO',
'operation' => '=', 'AU',
), 'NZ',
array( 'SG',
'type' => 'base_location_country', 'MY',
'value' => 'CZ', 'PH',
'operation' => '=', 'ID',
), 'VN',
array( 'TH',
'type' => 'base_location_country', 'KR',
'value' => 'DK', 'IL',
'operation' => '=', 'AE',
), 'RU',
array( 'UA',
'type' => 'base_location_country', 'TR',
'value' => 'FI', 'SA',
'operation' => '=', 'BR',
), 'JP',
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' => '=',
),
), ),
'operation' => 'in',
), ),
), ),
'is_built_by_wc' => false, 'is_built_by_wc' => false,
@ -997,63 +683,20 @@ class DefaultFreeExtensions {
*/ */
private static function get_rules_for_wcservices_tax_countries() { private static function get_rules_for_wcservices_tax_countries() {
return array( return array(
'type' => 'or', 'type' => 'base_location_country',
'operands' => array( 'operation' => 'in',
array( 'value' => array(
'type' => 'base_location_country', 'US',
'value' => 'US', 'FR',
'operation' => '=', 'GB',
), 'DE',
array( 'CA',
'type' => 'base_location_country', 'AU',
'value' => 'FR', 'GR',
'operation' => '=', 'BE',
), 'PT',
array( 'DK',
'type' => 'base_location_country', 'SE',
'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' => '=',
),
), ),
); );
} }