41827-improve-coupon-usage-by-user-query-performance (#43731)
The sql query can be slow on big data sets, because the post meta value is type of string, and we are quering with a number.
This commit is contained in:
parent
90b3e11dba
commit
4966697b7f
|
@ -0,0 +1,4 @@
|
|||
Significance: patch
|
||||
Type: update
|
||||
|
||||
Fix wpdb->prepare argument type for coupons query
|
|
@ -441,7 +441,7 @@ class WC_Coupon_Data_Store_CPT extends WC_Data_Store_WP implements WC_Coupon_Dat
|
|||
global $wpdb;
|
||||
$usage_count = $wpdb->get_var(
|
||||
$wpdb->prepare(
|
||||
"SELECT COUNT( meta_id ) FROM {$wpdb->postmeta} WHERE post_id = %d AND meta_key = '_used_by' AND meta_value = %d;",
|
||||
"SELECT COUNT( meta_id ) FROM {$wpdb->postmeta} WHERE post_id = %d AND meta_key = '_used_by' AND meta_value = %s;",
|
||||
$coupon->get_id(),
|
||||
$user_id
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue