-
Notifications
You must be signed in to change notification settings - Fork 55
Optimize order date generation #185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements chronological ordering for batch-generated orders by pre-generating and sorting dates before order creation. When date-start is specified in batch mode, orders created with lower IDs will have earlier or equal dates, ensuring a logical temporal sequence.
- Pre-generates dates for batch operations when
date-startis provided - Refactors date generation logic to use timestamp-based calculations instead of array enumeration
- Adds new
generate_batch_dates()method to handle batch date generation with chronological sorting
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
b042261 to
b37c787
Compare
|
Related to Test 3, I've added another PR because I don't think "Success: 0 orders generated…" is a very accurate message. ("Task failed successfully"): #189 |
chihsuan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great optimization! 💯 I was able to test it successfully according to the instructions. I just left a couple of minor suggestions.
Replaces inefficient date array building with direct timestamp calculation.
Builds on: #182
Problem
For each order, the old code built an array of all dates in the range (e.g., 664 dates for 2 years), then used array_rand(). For 500 orders over 2 years, this created 332,000 unnecessary date strings.
Solution
Calculate random offset directly using timestamps instead of building arrays.
Impact
Tests
Test 1: Batch generation with date range produces chronological orders
Expected: Order dates should be in ascending or equal order (no date inversions where later ID has earlier date)
Test 2: Same-day date range edge case
Expected: All orders created with date 2024-06-15 (different times, randomized)
Test 3: Error handling for failed order generation
# Attempt to create orders when no products exist (should skip failed orders gracefully) wp wc generate orders 5Expected: Error logged but batch continues; indicates 0 orders generated in the end.
Test 4: Large multi-year batch maintains chronological order
Expected: Date range covers the specified period with proper distribution