File tree Expand file tree Collapse file tree 1 file changed +9
-8
lines changed Expand file tree Collapse file tree 1 file changed +9
-8
lines changed Original file line number Diff line number Diff line change @@ -289,14 +289,15 @@ protected static function get_date_created( $assoc_args ) {
289289 return $ current ;
290290 }
291291
292- $ dates = array ();
293- $ date = strtotime ( $ start );
294- while ( $ date <= strtotime ( $ end ) ) {
295- $ dates [] = date ( 'Y-m-d ' , $ date );
296- $ date = strtotime ( '+1 day ' , $ date );
297- }
298-
299- return $ dates [ array_rand ( $ dates ) ];
292+ // Use timestamp-based random selection instead of building date array
293+ // This is much more efficient, especially for large date ranges
294+ $ start_timestamp = strtotime ( $ start );
295+ $ end_timestamp = strtotime ( $ end );
296+ $ days_between = (int ) ( ( $ end_timestamp - $ start_timestamp ) / DAY_IN_SECONDS );
297+
298+ // Generate random offset in days and add to start timestamp
299+ $ random_days = wp_rand ( 0 , $ days_between );
300+ return date ( 'Y-m-d ' , $ start_timestamp + ( $ random_days * DAY_IN_SECONDS ) );
300301 }
301302
302303 /**
You can’t perform that action at this time.
0 commit comments