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 @@ -256,14 +256,15 @@ protected static function get_date_created( $assoc_args ) {
256256 return $ current ;
257257 }
258258
259- $ dates = array ();
260- $ date = strtotime ( $ start );
261- while ( $ date <= strtotime ( $ end ) ) {
262- $ dates [] = date ( 'Y-m-d ' , $ date );
263- $ date = strtotime ( '+1 day ' , $ date );
264- }
265-
266- return $ dates [ array_rand ( $ dates ) ];
259+ // Use timestamp-based random selection instead of building date array
260+ // This is much more efficient, especially for large date ranges
261+ $ start_timestamp = strtotime ( $ start );
262+ $ end_timestamp = strtotime ( $ end );
263+ $ days_between = (int ) ( ( $ end_timestamp - $ start_timestamp ) / DAY_IN_SECONDS );
264+
265+ // Generate random offset in days and add to start timestamp
266+ $ random_days = wp_rand ( 0 , $ days_between );
267+ return date ( 'Y-m-d ' , $ start_timestamp + ( $ random_days * DAY_IN_SECONDS ) );
267268 }
268269
269270 /**
You can’t perform that action at this time.
0 commit comments