When updating multiple policies in the UI, the policies are now updated in series to reduce server/DB load. (#32212)

Fixes #31173 

# Checklist for submitter

- [x] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.

## Testing

- [x] QA'd all new/changed functionality manually
This commit is contained in:
Victor Lyuboslavsky 2025-08-25 10:02:52 -05:00 committed by GitHub
parent 4ce8a095c7
commit 2fd6a86f41
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 8 deletions

View file

@ -0,0 +1 @@
When updating multiple policies in the UI, the policies are now updated in series to reduce server/DB load.

View file

@ -572,15 +572,22 @@ const ManagePolicyPage = ({
return;
}
const promises = changedPolicies.map((changedPolicy) =>
teamPoliciesAPI.update(changedPolicy.id, {
software_title_id: changedPolicy.swIdToInstall || null,
team_id: teamIdForApi,
})
);
// Execute policy updates sequentially to reduce DB load
const results: PromiseSettledResult<any>[] = [];
// Allows for all API calls to settle even if there is an error on one
const results = await Promise.allSettled(promises);
// Use reduce to execute promises sequentially
await changedPolicies.reduce(async (previousPromise, changedPolicy) => {
await previousPromise;
try {
const result = await teamPoliciesAPI.update(changedPolicy.id, {
software_title_id: changedPolicy.swIdToInstall || null,
team_id: teamIdForApi,
});
results.push({ status: "fulfilled", value: result });
} catch (error) {
results.push({ status: "rejected", reason: error });
}
}, Promise.resolve());
const successfulUpdates = results.filter(
(result) => result.status === "fulfilled"