fix(deletion): delete objects batch by batch EE-7084 (#11833)
parent
00ab9e949a
commit
3924d0f081
|
@ -3,6 +3,7 @@ import { PorImageRegistryModel } from 'Docker/models/porImageRegistry';
|
||||||
import { confirmImageExport } from '@/react/docker/images/common/ConfirmExportModal';
|
import { confirmImageExport } from '@/react/docker/images/common/ConfirmExportModal';
|
||||||
import { confirmDestructive } from '@@/modals/confirm';
|
import { confirmDestructive } from '@@/modals/confirm';
|
||||||
import { buildConfirmButton } from '@@/modals/utils';
|
import { buildConfirmButton } from '@@/modals/utils';
|
||||||
|
import { processItemsInBatches } from '@/react/common/processItemsInBatches';
|
||||||
|
|
||||||
angular.module('portainer.docker').controller('ImagesController', [
|
angular.module('portainer.docker').controller('ImagesController', [
|
||||||
'$scope',
|
'$scope',
|
||||||
|
@ -157,24 +158,20 @@ angular.module('portainer.docker').controller('ImagesController', [
|
||||||
* @param {Array<import('@/react/docker/images/queries/useImages').ImagesListResponse>} selectedItems
|
* @param {Array<import('@/react/docker/images/queries/useImages').ImagesListResponse>} selectedItems
|
||||||
* @param {boolean} force
|
* @param {boolean} force
|
||||||
*/
|
*/
|
||||||
function removeAction(selectedItems, force) {
|
async function removeAction(selectedItems, force) {
|
||||||
var actionCount = selectedItems.length;
|
async function doRemove(image) {
|
||||||
angular.forEach(selectedItems, function (image) {
|
|
||||||
HttpRequestHelper.setPortainerAgentTargetHeader(image.nodeName);
|
HttpRequestHelper.setPortainerAgentTargetHeader(image.nodeName);
|
||||||
ImageService.deleteImage(image.id, force)
|
return ImageService.deleteImage(image.id, force)
|
||||||
.then(function success() {
|
.then(function success() {
|
||||||
Notifications.success('Image successfully removed', image.id);
|
Notifications.success('Image successfully removed', image.id);
|
||||||
})
|
})
|
||||||
.catch(function error(err) {
|
.catch(function error(err) {
|
||||||
Notifications.error('Failure', err, 'Unable to remove image');
|
Notifications.error('Failure', err, 'Unable to remove image');
|
||||||
})
|
|
||||||
.finally(function final() {
|
|
||||||
--actionCount;
|
|
||||||
if (actionCount === 0) {
|
|
||||||
$state.reload();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
|
||||||
|
await processItemsInBatches(selectedItems, doRemove);
|
||||||
|
$state.reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.setPullImageValidity = setPullImageValidity;
|
$scope.setPullImageValidity = setPullImageValidity;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import _ from 'lodash-es';
|
import _ from 'lodash-es';
|
||||||
import DockerNetworkHelper from '@/docker/helpers/networkHelper';
|
import DockerNetworkHelper from '@/docker/helpers/networkHelper';
|
||||||
|
import { processItemsInBatches } from '@/react/common/processItemsInBatches';
|
||||||
|
|
||||||
angular.module('portainer.docker').controller('NetworksController', [
|
angular.module('portainer.docker').controller('NetworksController', [
|
||||||
'$q',
|
'$q',
|
||||||
|
@ -12,10 +13,9 @@ angular.module('portainer.docker').controller('NetworksController', [
|
||||||
'AgentService',
|
'AgentService',
|
||||||
function ($q, $scope, $state, NetworkService, Notifications, HttpRequestHelper, endpoint, AgentService) {
|
function ($q, $scope, $state, NetworkService, Notifications, HttpRequestHelper, endpoint, AgentService) {
|
||||||
$scope.removeAction = async function (selectedItems) {
|
$scope.removeAction = async function (selectedItems) {
|
||||||
var actionCount = selectedItems.length;
|
async function doRemove(network) {
|
||||||
angular.forEach(selectedItems, function (network) {
|
|
||||||
HttpRequestHelper.setPortainerAgentTargetHeader(network.NodeName);
|
HttpRequestHelper.setPortainerAgentTargetHeader(network.NodeName);
|
||||||
NetworkService.remove(network.Id)
|
return NetworkService.remove(network.Id)
|
||||||
.then(function success() {
|
.then(function success() {
|
||||||
Notifications.success('Network successfully removed', network.Name);
|
Notifications.success('Network successfully removed', network.Name);
|
||||||
var index = $scope.networks.indexOf(network);
|
var index = $scope.networks.indexOf(network);
|
||||||
|
@ -23,14 +23,11 @@ angular.module('portainer.docker').controller('NetworksController', [
|
||||||
})
|
})
|
||||||
.catch(function error(err) {
|
.catch(function error(err) {
|
||||||
Notifications.error('Failure', err, 'Unable to remove network');
|
Notifications.error('Failure', err, 'Unable to remove network');
|
||||||
})
|
|
||||||
.finally(function final() {
|
|
||||||
--actionCount;
|
|
||||||
if (actionCount === 0) {
|
|
||||||
$state.reload();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
|
||||||
|
await processItemsInBatches(selectedItems, doRemove);
|
||||||
|
$state.reload();
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.getNetworks = getNetworks;
|
$scope.getNetworks = getNetworks;
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import { processItemsInBatches } from '@/react/common/processItemsInBatches';
|
||||||
|
|
||||||
angular.module('portainer.docker').controller('SecretsController', [
|
angular.module('portainer.docker').controller('SecretsController', [
|
||||||
'$scope',
|
'$scope',
|
||||||
'$state',
|
'$state',
|
||||||
|
@ -5,9 +7,8 @@ angular.module('portainer.docker').controller('SecretsController', [
|
||||||
'Notifications',
|
'Notifications',
|
||||||
function ($scope, $state, SecretService, Notifications) {
|
function ($scope, $state, SecretService, Notifications) {
|
||||||
$scope.removeAction = async function (selectedItems) {
|
$scope.removeAction = async function (selectedItems) {
|
||||||
var actionCount = selectedItems.length;
|
async function doRemove(secret) {
|
||||||
angular.forEach(selectedItems, function (secret) {
|
return SecretService.remove(secret.Id)
|
||||||
SecretService.remove(secret.Id)
|
|
||||||
.then(function success() {
|
.then(function success() {
|
||||||
Notifications.success('Secret successfully removed', secret.Name);
|
Notifications.success('Secret successfully removed', secret.Name);
|
||||||
var index = $scope.secrets.indexOf(secret);
|
var index = $scope.secrets.indexOf(secret);
|
||||||
|
@ -15,14 +16,11 @@ angular.module('portainer.docker').controller('SecretsController', [
|
||||||
})
|
})
|
||||||
.catch(function error(err) {
|
.catch(function error(err) {
|
||||||
Notifications.error('Failure', err, 'Unable to remove secret');
|
Notifications.error('Failure', err, 'Unable to remove secret');
|
||||||
})
|
|
||||||
.finally(function final() {
|
|
||||||
--actionCount;
|
|
||||||
if (actionCount === 0) {
|
|
||||||
$state.reload();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
|
||||||
|
await processItemsInBatches(selectedItems, doRemove);
|
||||||
|
$state.reload();
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.getSecrets = getSecrets;
|
$scope.getSecrets = getSecrets;
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import { processItemsInBatches } from '@/react/common/processItemsInBatches';
|
||||||
|
|
||||||
angular.module('portainer.docker').controller('VolumesController', [
|
angular.module('portainer.docker').controller('VolumesController', [
|
||||||
'$q',
|
'$q',
|
||||||
'$scope',
|
'$scope',
|
||||||
|
@ -10,11 +12,10 @@ angular.module('portainer.docker').controller('VolumesController', [
|
||||||
'Authentication',
|
'Authentication',
|
||||||
'endpoint',
|
'endpoint',
|
||||||
function ($q, $scope, $state, VolumeService, ServiceService, VolumeHelper, Notifications, HttpRequestHelper, Authentication, endpoint) {
|
function ($q, $scope, $state, VolumeService, ServiceService, VolumeHelper, Notifications, HttpRequestHelper, Authentication, endpoint) {
|
||||||
$scope.removeAction = function (selectedItems) {
|
$scope.removeAction = async function (selectedItems) {
|
||||||
var actionCount = selectedItems.length;
|
async function doRemove(volume) {
|
||||||
angular.forEach(selectedItems, function (volume) {
|
|
||||||
HttpRequestHelper.setPortainerAgentTargetHeader(volume.NodeName);
|
HttpRequestHelper.setPortainerAgentTargetHeader(volume.NodeName);
|
||||||
VolumeService.remove(volume)
|
return VolumeService.remove(volume)
|
||||||
.then(function success() {
|
.then(function success() {
|
||||||
Notifications.success('Volume successfully removed', volume.Id);
|
Notifications.success('Volume successfully removed', volume.Id);
|
||||||
var index = $scope.volumes.indexOf(volume);
|
var index = $scope.volumes.indexOf(volume);
|
||||||
|
@ -22,14 +23,11 @@ angular.module('portainer.docker').controller('VolumesController', [
|
||||||
})
|
})
|
||||||
.catch(function error(err) {
|
.catch(function error(err) {
|
||||||
Notifications.error('Failure', err, 'Unable to remove volume');
|
Notifications.error('Failure', err, 'Unable to remove volume');
|
||||||
})
|
|
||||||
.finally(function final() {
|
|
||||||
--actionCount;
|
|
||||||
if (actionCount === 0) {
|
|
||||||
$state.reload();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
|
||||||
|
await processItemsInBatches(selectedItems, doRemove);
|
||||||
|
$state.reload();
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.getVolumes = getVolumes;
|
$scope.getVolumes = getVolumes;
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import { processItemsInBatches } from '@/react/common/processItemsInBatches';
|
||||||
|
|
||||||
angular.module('portainer.app').controller('StacksController', StacksController);
|
angular.module('portainer.app').controller('StacksController', StacksController);
|
||||||
|
|
||||||
/* @ngInject */
|
/* @ngInject */
|
||||||
|
@ -6,11 +8,11 @@ function StacksController($scope, $state, Notifications, StackService, Authentic
|
||||||
return deleteSelectedStacks(selectedItems);
|
return deleteSelectedStacks(selectedItems);
|
||||||
};
|
};
|
||||||
|
|
||||||
function deleteSelectedStacks(stacks) {
|
async function deleteSelectedStacks(selectedItems) {
|
||||||
const endpointId = endpoint.Id;
|
const endpointId = endpoint.Id;
|
||||||
let actionCount = stacks.length;
|
|
||||||
angular.forEach(stacks, function (stack) {
|
async function doRemove(stack) {
|
||||||
StackService.remove(stack, stack.External, endpointId)
|
return StackService.remove(stack, stack.External, endpointId)
|
||||||
.then(function success() {
|
.then(function success() {
|
||||||
Notifications.success('Stack successfully removed', stack.Name);
|
Notifications.success('Stack successfully removed', stack.Name);
|
||||||
var index = $scope.stacks.indexOf(stack);
|
var index = $scope.stacks.indexOf(stack);
|
||||||
|
@ -18,14 +20,11 @@ function StacksController($scope, $state, Notifications, StackService, Authentic
|
||||||
})
|
})
|
||||||
.catch(function error(err) {
|
.catch(function error(err) {
|
||||||
Notifications.error('Failure', err, 'Unable to remove stack ' + stack.Name);
|
Notifications.error('Failure', err, 'Unable to remove stack ' + stack.Name);
|
||||||
})
|
|
||||||
.finally(function final() {
|
|
||||||
--actionCount;
|
|
||||||
if (actionCount === 0) {
|
|
||||||
$state.reload();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
|
||||||
|
await processItemsInBatches(selectedItems, doRemove);
|
||||||
|
$state.reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.createEnabled = false;
|
$scope.createEnabled = false;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import _ from 'lodash-es';
|
import _ from 'lodash-es';
|
||||||
import { AuthenticationMethod } from '@/react/portainer/settings/types';
|
import { AuthenticationMethod } from '@/react/portainer/settings/types';
|
||||||
|
import { processItemsInBatches } from '@/react/common/processItemsInBatches';
|
||||||
|
|
||||||
angular.module('portainer.app').controller('UsersController', [
|
angular.module('portainer.app').controller('UsersController', [
|
||||||
'$q',
|
'$q',
|
||||||
|
@ -69,10 +70,9 @@ angular.module('portainer.app').controller('UsersController', [
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
function deleteSelectedUsers(selectedItems) {
|
async function deleteSelectedUsers(selectedItems) {
|
||||||
var actionCount = selectedItems.length;
|
async function doRemove(user) {
|
||||||
angular.forEach(selectedItems, function (user) {
|
return UserService.deleteUser(user.Id)
|
||||||
UserService.deleteUser(user.Id)
|
|
||||||
.then(function success() {
|
.then(function success() {
|
||||||
Notifications.success('User successfully removed', user.Username);
|
Notifications.success('User successfully removed', user.Username);
|
||||||
var index = $scope.users.indexOf(user);
|
var index = $scope.users.indexOf(user);
|
||||||
|
@ -80,14 +80,10 @@ angular.module('portainer.app').controller('UsersController', [
|
||||||
})
|
})
|
||||||
.catch(function error(err) {
|
.catch(function error(err) {
|
||||||
Notifications.error('Failure', err, 'Unable to remove user');
|
Notifications.error('Failure', err, 'Unable to remove user');
|
||||||
})
|
|
||||||
.finally(function final() {
|
|
||||||
--actionCount;
|
|
||||||
if (actionCount === 0) {
|
|
||||||
$state.reload();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
await processItemsInBatches(selectedItems, doRemove);
|
||||||
|
$state.reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.removeAction = function (selectedItems) {
|
$scope.removeAction = function (selectedItems) {
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
/**
|
||||||
|
* Type definition for the callback function used in processItemsInBatches.
|
||||||
|
* It should accept an item from the array as its first argument
|
||||||
|
* and additional arguments (if any) as its second argument, and should return a Promise.
|
||||||
|
*/
|
||||||
|
type ProcessItemsCallback<T, Args extends never[]> = (
|
||||||
|
item: T,
|
||||||
|
...args: Args
|
||||||
|
) => Promise<void>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asynchronously processes an array of items in batches.
|
||||||
|
* @param items An array of items to be processed.
|
||||||
|
* @param processor A callback function of type ProcessItemsCallback that will be called for each item in the array.
|
||||||
|
* @param batchSize The maximum number of items to process in each batch. Defaults to 100 if not provided.
|
||||||
|
* @param args Additional arguments to be passed to the callback function for each item.
|
||||||
|
*/
|
||||||
|
export async function processItemsInBatches<T, Args extends never[]>(
|
||||||
|
items: T[],
|
||||||
|
processor: ProcessItemsCallback<T, Args>,
|
||||||
|
batchSize = 100,
|
||||||
|
...args: Args
|
||||||
|
): Promise<void> {
|
||||||
|
while (items.length) {
|
||||||
|
const batch = items.splice(0, batchSize);
|
||||||
|
const batchPromises = batch.map((item) => processor(item, ...args));
|
||||||
|
|
||||||
|
await Promise.all(batchPromises);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue