Refactor SQL for segment in country to use join instead subselect

[MAILPOET-3226]
This commit is contained in:
Rostislav Wolny
2021-05-10 15:16:26 +02:00
committed by Veljko V
parent 1ec4300153
commit d4fbe95aef

View File

@@ -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"