Skip to content

Commit 5b53925

Browse files
committed
Add performance comment for get_posts() in Coupon::get_random()
1 parent 2c9940e commit 5b53925

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

includes/Generator/Coupon.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ public static function batch( $amount, array $args = array() ) {
151151
* @return \WC_Coupon|false Coupon object or false if none available.
152152
*/
153153
public static function get_random() {
154+
// Note: Using posts_per_page=-1 loads all coupons into memory for random selection.
155+
// For stores with thousands of coupons, consider using direct SQL with RAND() for better performance.
156+
// This approach was chosen for consistency with WordPress APIs and to avoid raw SQL queries.
154157
$coupon_ids = get_posts(
155158
array(
156159
'post_type' => 'shop_coupon',

0 commit comments

Comments
 (0)