diff --git a/changelog/fix-3693-qualitative-feedback-note b/changelog/fix-3693-qualitative-feedback-note new file mode 100644 index 00000000000..8862cc0c961 --- /dev/null +++ b/changelog/fix-3693-qualitative-feedback-note @@ -0,0 +1,4 @@ +Significance: patch +Type: fix + +Update Qualitative Feedback note to have more efficient sql query. diff --git a/includes/notes/class-wc-payments-notes-qualitative-feedback.php b/includes/notes/class-wc-payments-notes-qualitative-feedback.php index 266e1dd70f1..031fbd6b473 100644 --- a/includes/notes/class-wc-payments-notes-qualitative-feedback.php +++ b/includes/notes/class-wc-payments-notes-qualitative-feedback.php @@ -38,8 +38,27 @@ public static function get_note() { } // We should have at least one transaction. - $token_count = $wpdb->get_var( "select count(*) from {$wpdb->prefix}woocommerce_payment_tokens" ); - if ( 0 === (int) $token_count ) { + if ( WC_Payments_Utils::is_hpos_tables_usage_enabled() ) { + $result = $wpdb->get_var( + "SELECT EXISTS( + SELECT 1 + FROM {$wpdb->prefix}wc_orders_meta + WHERE meta_key = '_wcpay_transaction_fee' + LIMIT 1) + AS count;" + ); + } else { + $result = $wpdb->get_var( + "SELECT EXISTS( + SELECT 1 + FROM {$wpdb->postmeta} + WHERE meta_key = '_wcpay_transaction_fee' + LIMIT 1) + AS count;" + ); + } + + if ( 1 !== intval( $result ) ) { return; }