From a1bf7ec23fcb0901792882d131a5cae38f8711ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ja=CC=81n=20Mikla=CC=81s=CC=8C?= Date: Wed, 14 Aug 2019 14:00:49 +0200 Subject: [PATCH] More performant check if there are any WC users [MAILPOET-2163] --- lib/Models/Segment.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/Models/Segment.php b/lib/Models/Segment.php index e4163dcfc0..4350700407 100644 --- a/lib/Models/Segment.php +++ b/lib/Models/Segment.php @@ -159,9 +159,17 @@ class Segment extends Model { static function shouldShowWooCommerceSegment() { $woocommerce_helper = new WCHelper(); $is_woocommerce_active = $woocommerce_helper->isWooCommerceActive(); - $woocommerce_users_count = Subscriber::where('is_woocommerce_user', 1)->count(); + $woocommerce_user_exists = Segment::tableAlias('segment') + ->where('segment.type', Segment::TYPE_WC_USERS) + ->join( + MP_SUBSCRIBER_SEGMENT_TABLE, + 'segment_subscribers.segment_id = segment.id', + 'segment_subscribers' + ) + ->limit(1) + ->findOne(); - if (!$is_woocommerce_active && $woocommerce_users_count === 0) { + if (!$is_woocommerce_active && !$woocommerce_user_exists) { return false; } return true;