mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-05-24 09:14:47 +01:00
fix: Implement abort functionality for bulk document deletion (#2139)
This commit is contained in:
parent
7aeb682bea
commit
15154dfd6a
@ -2869,6 +2869,7 @@ a:link {
|
|||||||
z-index: 1000;
|
z-index: 1000;
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
overflow-x: clip;
|
overflow-x: clip;
|
||||||
|
min-height: fit-content;
|
||||||
}
|
}
|
||||||
|
|
||||||
.uniqueIndexesContainer {
|
.uniqueIndexesContainer {
|
||||||
|
@ -42,6 +42,7 @@ export interface IBulkDeleteResult {
|
|||||||
export const deleteDocuments = async (
|
export const deleteDocuments = async (
|
||||||
collection: CollectionBase,
|
collection: CollectionBase,
|
||||||
documentIds: DocumentId[],
|
documentIds: DocumentId[],
|
||||||
|
abortSignal: AbortSignal,
|
||||||
): Promise<IBulkDeleteResult[]> => {
|
): Promise<IBulkDeleteResult[]> => {
|
||||||
const clearMessage = logConsoleProgress(`Deleting ${documentIds.length} ${getEntityName(true)}`);
|
const clearMessage = logConsoleProgress(`Deleting ${documentIds.length} ${getEntityName(true)}`);
|
||||||
try {
|
try {
|
||||||
@ -65,7 +66,11 @@ export const deleteDocuments = async (
|
|||||||
operationType: BulkOperationType.Delete,
|
operationType: BulkOperationType.Delete,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const promise = v2Container.items.bulk(operations).then((bulkResults) => {
|
const promise = v2Container.items
|
||||||
|
.bulk(operations, undefined, {
|
||||||
|
abortSignal,
|
||||||
|
})
|
||||||
|
.then((bulkResults) => {
|
||||||
return bulkResults.map((bulkResult, index) => {
|
return bulkResults.map((bulkResult, index) => {
|
||||||
const documentId = documentIdsChunk[index];
|
const documentId = documentIdsChunk[index];
|
||||||
return { ...bulkResult, documentId };
|
return { ...bulkResult, documentId };
|
||||||
|
@ -679,6 +679,7 @@ export const DocumentsTabComponent: React.FunctionComponent<IDocumentsTabCompone
|
|||||||
collection: CollectionBase;
|
collection: CollectionBase;
|
||||||
}>(undefined);
|
}>(undefined);
|
||||||
const [bulkDeleteMode, setBulkDeleteMode] = useState<"inProgress" | "completed" | "aborting" | "aborted">(undefined);
|
const [bulkDeleteMode, setBulkDeleteMode] = useState<"inProgress" | "completed" | "aborting" | "aborted">(undefined);
|
||||||
|
const [abortController, setAbortController] = useState<AbortController | undefined>(undefined);
|
||||||
|
|
||||||
const setKeyboardActions = useKeyboardActionGroup(KeyboardActionGroup.ACTIVE_TAB);
|
const setKeyboardActions = useKeyboardActionGroup(KeyboardActionGroup.ACTIVE_TAB);
|
||||||
|
|
||||||
@ -706,13 +707,19 @@ export const DocumentsTabComponent: React.FunctionComponent<IDocumentsTabCompone
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (bulkDeleteProcess.pendingIds.length === 0 && bulkDeleteProcess.throttledIds.length === 0) {
|
||||||
(bulkDeleteProcess.pendingIds.length === 0 && bulkDeleteProcess.throttledIds.length === 0) ||
|
// Successfully deleted all documents
|
||||||
bulkDeleteMode === "aborting"
|
|
||||||
) {
|
|
||||||
// Successfully deleted all documents or operation was aborted
|
|
||||||
bulkDeleteOperation.onCompleted(bulkDeleteProcess.successfulIds);
|
bulkDeleteOperation.onCompleted(bulkDeleteProcess.successfulIds);
|
||||||
setBulkDeleteMode(bulkDeleteMode === "aborting" ? "aborted" : "completed");
|
setBulkDeleteMode("completed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bulkDeleteMode === "aborting") {
|
||||||
|
// Operation was aborted
|
||||||
|
abortController?.abort();
|
||||||
|
bulkDeleteOperation.onCompleted(bulkDeleteProcess.successfulIds);
|
||||||
|
setBulkDeleteMode("aborted");
|
||||||
|
setAbortController(undefined);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -720,8 +727,10 @@ export const DocumentsTabComponent: React.FunctionComponent<IDocumentsTabCompone
|
|||||||
const newPendingIds = bulkDeleteProcess.pendingIds.concat(bulkDeleteProcess.throttledIds);
|
const newPendingIds = bulkDeleteProcess.pendingIds.concat(bulkDeleteProcess.throttledIds);
|
||||||
const timeout = bulkDeleteProcess.beforeExecuteMs || 0;
|
const timeout = bulkDeleteProcess.beforeExecuteMs || 0;
|
||||||
|
|
||||||
|
const ac = new AbortController();
|
||||||
|
setAbortController(ac);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
deleteNoSqlDocuments(bulkDeleteOperation.collection, [...newPendingIds])
|
deleteNoSqlDocuments(bulkDeleteOperation.collection, [...newPendingIds], ac.signal)
|
||||||
.then((deleteResult) => {
|
.then((deleteResult) => {
|
||||||
let retryAfterMilliseconds = 0;
|
let retryAfterMilliseconds = 0;
|
||||||
const newSuccessful: DocumentId[] = [];
|
const newSuccessful: DocumentId[] = [];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user