fix: ensure order is preserved in Promise.all of adjustments#5920
fix: ensure order is preserved in Promise.all of adjustments#5920yuda110 merged 1 commit intocloudforet-io:developfrom
Conversation
Signed-off-by: yuda <yuda@megazone.com>
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
2 Skipped Deployments
|
|
@yuda110 is attempting to deploy a commit to the cloudforet Team on Vercel. A member of the Team first needs to authorize it. |
|
🎉 @seungyeoneeee has been randomly selected as the reviewer! Please review. 🙏 |
There was a problem hiding this comment.
Pull Request Overview
This PR replaces concurrent Promise.all execution with sequential promise chaining to ensure that order is preserved during adjustment policy and adjustment processing.
- Processes adjustment policies sequentially by replacing a map/Promise.all pattern with an async reduce chain.
- Updates adjustment processing similarly to enforce sequential execution.
Comments suppressed due to low confidence (1)
apps/web/src/services/cost-explorer/components/AdvancedSettingsSetAdjustmentsOverlay.vue:235
- The sequential processing of adjustments via reduce enforces order, but it may be less performant than parallel execution if order is not critical. Please confirm that preserving order is a necessary requirement.
await formPolicies.value.reduce(async (promise, policy) => {
| await formPolicies.value.reduce(async (promise, policy, idx) => { | ||
| await promise; | ||
| if (policy.id.startsWith('rap-')) { | ||
| return updateAdjustmentPolicy(policy, idx); | ||
| } | ||
| return createAdjustmentPolicy(policy, idx); | ||
| }); | ||
| await Promise.all(policyPromises); | ||
| }, Promise.resolve()); | ||
|
|
||
| // CUD Adjustment | ||
| await deleteAdjustment(deletedPolicyIds); | ||
| const adjustmentPromises = formPolicies.value.flatMap(async (policy) => { | ||
| await formPolicies.value.reduce(async (promise, policy) => { | ||
| await promise; | ||
| const adjustments = formAdjustments.value.filter((adjustment) => adjustment.policyId === policy.id); | ||
| return adjustments.map(async (adjustment, idx) => { | ||
| return adjustments.reduce(async (adjPromise, adjustment, idx) => { | ||
| await adjPromise; | ||
| if (adjustment.id.startsWith('ra-')) { | ||
| return updateAdjustment(adjustment, idx); | ||
| } | ||
| return createAdjustment(adjustment, idx); | ||
| }); | ||
| }); | ||
| const resolvedAdjustments = await Promise.all(adjustmentPromises); | ||
| await Promise.all(resolvedAdjustments.flat()); | ||
| }, Promise.resolve()); | ||
| }, Promise.resolve()); |
There was a problem hiding this comment.
Switching to sequential execution ensures order preservation, but may introduce performance overhead with large policy arrays. Consider documenting the performance trade-off if sequential processing is required.
Skip Review (optional)
style,chore,ci,test,docs)Description (optional)
Things to Talk About (optional)