From d4fbe95aefcc6e322d3187a10db932c8890f0d0c Mon Sep 17 00:00:00 2001 From: Rostislav Wolny Date: Mon, 10 May 2021 15:16:26 +0200 Subject: [PATCH] Refactor SQL for segment in country to use join instead subselect [MAILPOET-3226] --- .../DynamicSegments/Filters/WooCommerceCountry.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/Segments/DynamicSegments/Filters/WooCommerceCountry.php b/lib/Segments/DynamicSegments/Filters/WooCommerceCountry.php index 1091ab9905..7380d69faa 100644 --- a/lib/Segments/DynamicSegments/Filters/WooCommerceCountry.php +++ b/lib/Segments/DynamicSegments/Filters/WooCommerceCountry.php @@ -27,10 +27,14 @@ class WooCommerceCountry implements Filter { $subscribersTable, $wpdb->postmeta, 'postmeta', - "postmeta.meta_key = '_customer_user' - AND $subscribersTable.wp_user_id=postmeta.meta_value - AND postmeta.post_id NOT IN ( SELECT id FROM {$wpdb->posts} as p WHERE p.post_status IN ('wc-cancelled', 'wc-failed'))" - )->innerJoin('postmeta', + "postmeta.meta_key = '_customer_user' AND $subscribersTable.wp_user_id=postmeta.meta_value" + )->innerJoin( + 'postmeta', + $wpdb->posts, + 'posts', + "postmeta.post_id = posts.id AND posts.post_status NOT IN ('wc-cancelled', 'wc-failed')" + )->innerJoin( + 'postmeta', $wpdb->postmeta, 'postmetaCountry', "postmeta.post_id = postmetaCountry.post_id AND postmetaCountry.meta_key = '_billing_country' AND postmetaCountry.meta_value = :$countryFilterParam"