From 11b98493eaddd5d7d97adc4d580c7fbca454362d Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Sun, 28 Jul 2024 17:28:51 +0200 Subject: [PATCH] fix: Make it pass unidirectional tests Signed-off-by: Marcel Klehr --- src/lib/Diff.ts | 2 +- src/lib/strategies/Unidirectional.ts | 26 +++++++++++++++----------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/lib/Diff.ts b/src/lib/Diff.ts index 1a7ba70b49..a39dac4199 100644 --- a/src/lib/Diff.ts +++ b/src/lib/Diff.ts @@ -299,7 +299,7 @@ export interface PlanStage3 { CREATE: Diff> UPDATE: Diff> - MOVE: Diff> + MOVE: Diff> REMOVE: Diff> REORDER: Diff> } diff --git a/src/lib/strategies/Unidirectional.ts b/src/lib/strategies/Unidirectional.ts index b99036ef51..d7d3505bd3 100644 --- a/src/lib/strategies/Unidirectional.ts +++ b/src/lib/strategies/Unidirectional.ts @@ -162,7 +162,11 @@ export default class UnidirectionalSyncProcess extends DefaultStrategy { } } - async revertDiff(targetScanResult: ScanResult, sourceScanResult: ScanResult, targetLocation: L1): Promise> { + async revertDiff( + targetScanResult: ScanResult, + sourceScanResult: ScanResult, + targetLocation: L1 + ): Promise> { const mappingsSnapshot = this.mappings.getSnapshot() const slavePlan: PlanRevert = { @@ -201,15 +205,11 @@ export default class UnidirectionalSyncProcess extends DefaultStrategy { }, ACTION_CONCURRENCY) await Parallel.each(targetScanResult.MOVE.getActions(), async(action) => { - const oldPayload = action.payload.cloneWithLocation(false, action.oldItem.location) - oldPayload.id = action.oldItem.id - oldPayload.parentId = action.oldItem.parentId + const payload = action.payload.cloneWithLocation(false, action.oldItem.location) + payload.id = action.oldItem.id + payload.parentId = action.oldItem.parentId - const oldOldItem = action.oldItem.cloneWithLocation(false, action.payload.location) - oldOldItem.id = action.payload.id - oldOldItem.parentId = action.payload.parentId - - slavePlan.MOVE.commit({ type: ActionType.MOVE, payload: oldOldItem, oldItem: oldPayload }) + slavePlan.MOVE.commit({ type: ActionType.MOVE, payload }) // no oldItem, because we want to map the id after having executed the CREATEs }, ACTION_CONCURRENCY) return slavePlan @@ -275,11 +275,15 @@ export default class UnidirectionalSyncProcess extends DefaultStrategy { throw new CancelledSyncError() } + const mappingsSnapshot = this.mappings.getSnapshot() + // TODO: Store this in continuation + const mappedMoves = planRevert.MOVE.map(mappingsSnapshot, targetLocation) + if (this.canceled) { throw new CancelledSyncError() } - const batches = Diff.sortMoves(planRevert.MOVE.getActions(), this.getTargetTree(targetLocation)) + const batches = Diff.sortMoves(mappedMoves.getActions(), this.getTargetTree(targetLocation)) if (this.canceled) { throw new CancelledSyncError() @@ -287,7 +291,7 @@ export default class UnidirectionalSyncProcess extends DefaultStrategy { Logger.log(targetLocation + ': executing MOVEs') await Parallel.each(batches, batch => Parallel.each(batch, (action) => { - return this.executeUpdate(resource, action, targetLocation, planRevert.MOVE, donePlan) + return this.executeUpdate(resource, action, targetLocation, mappedMoves, donePlan) }, ACTION_CONCURRENCY), 1) if (this.canceled) {