mirror of
https://github.com/fleetdm/fleet
synced 2026-04-21 13:37:30 +00:00
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:
parent
4ce8a095c7
commit
2fd6a86f41
2 changed files with 16 additions and 8 deletions
1
changes/31173-fix-policy-deadlocks-frontend
Normal file
1
changes/31173-fix-policy-deadlocks-frontend
Normal file
|
|
@ -0,0 +1 @@
|
|||
When updating multiple policies in the UI, the policies are now updated in series to reduce server/DB load.
|
||||
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Reference in a new issue