mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
Merge pull request #2790 from DSpace/backport-2778-to-dspace-7_x
[Port dspace-7_x] Dedupe patch operations by op and path
This commit is contained in:
@@ -351,7 +351,28 @@ function addOperationToList(body: JsonPatchOperationObject[], actionType, target
|
|||||||
newBody.push(makeOperationEntry({ op: JsonPatchOperationType.move, from: fromPath, path: targetPath }));
|
newBody.push(makeOperationEntry({ op: JsonPatchOperationType.move, from: fromPath, path: targetPath }));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return newBody;
|
return dedupeOperationEntries(newBody);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dedupe operation entries by op and path. This prevents processing unnecessary patches in a single PATCH request.
|
||||||
|
*
|
||||||
|
* @param body JSON patch operation object entries
|
||||||
|
* @returns deduped JSON patch operation object entries
|
||||||
|
*/
|
||||||
|
function dedupeOperationEntries(body: JsonPatchOperationObject[]): JsonPatchOperationObject[] {
|
||||||
|
const ops = new Map<string, any>();
|
||||||
|
for (let i = body.length - 1; i >= 0; i--) {
|
||||||
|
const patch = body[i].operation;
|
||||||
|
const key = `${patch.op}-${patch.path}`;
|
||||||
|
if (!ops.has(key)) {
|
||||||
|
ops.set(key, patch);
|
||||||
|
} else {
|
||||||
|
body.splice(i, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
function makeOperationEntry(operation) {
|
function makeOperationEntry(operation) {
|
||||||
|
Reference in New Issue
Block a user