Skip to content

Commit df6ab03

Browse files
committed
fix(SyncProcess): Apply skipErroneousActions broadly
to handle actions with missing mappings in the next sync run Signed-off-by: Marcel Klehr <mklehr@gmx.net>
1 parent 465d398 commit df6ab03

2 files changed

Lines changed: 26 additions & 4 deletions

File tree

src/lib/Diff.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,16 @@ export default class Diff<
334334
targetLocation
335335
)
336336
if (action.type !== ActionType.CREATE && typeof action.payload.id !== 'undefined' && typeof newAction.payload.id === 'undefined') {
337+
if (skipErroneousActions) {
338+
// The action references an item that has no counterpart on the target, so it
339+
// can't be applied (e.g. a MOVE of an item that no longer exists there). Drop
340+
// it rather than throwing — the alternative (MappingFailureError) triggers a
341+
// reset-cache + forceSync recovery that re-applies already-committed actions
342+
// and duplicates them on non-atomic servers. A subsequent sync reconciles the
343+
// item afresh if it's still relevant.
344+
Logger.log('Failed to map id: ' + action.payload.id + ' — dropping action from plan as no longer valid')
345+
return
346+
}
337347
Logger.log(
338348
'payload.location = ' +
339349
action.payload.location +

src/lib/strategies/Default.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,10 @@ export default class SyncProcess {
437437
this.planStage3Server = {
438438
CREATE: this.serverPlanStage2.CREATE,
439439
UPDATE: this.serverPlanStage2.UPDATE,
440-
MOVE: this.serverPlanStage2.MOVE.map(mappingsSnapshot, ItemLocation.SERVER),
440+
// skipErroneousActions: a MOVE whose item can no longer be mapped to the target is
441+
// unapplyable; drop it instead of throwing MappingFailureError (which would force a
442+
// cache reset + from-scratch resync that duplicates on non-atomic servers).
443+
MOVE: this.serverPlanStage2.MOVE.map(mappingsSnapshot, ItemLocation.SERVER, () => true, true),
441444
REMOVE: this.serverPlanStage2.REMOVE,
442445
REORDER: this.serverPlanStage2.REORDER,
443446
}
@@ -471,7 +474,8 @@ export default class SyncProcess {
471474
this.planStage3Local = {
472475
CREATE: this.localPlanStage2.CREATE,
473476
UPDATE: this.localPlanStage2.UPDATE,
474-
MOVE: this.localPlanStage2.MOVE.map(mappingsSnapshot, ItemLocation.LOCAL),
477+
// skipErroneousActions: see the server stage 3 plan above.
478+
MOVE: this.localPlanStage2.MOVE.map(mappingsSnapshot, ItemLocation.LOCAL, () => true, true),
475479
REMOVE: this.localPlanStage2.REMOVE,
476480
REORDER: this.localPlanStage2.REORDER,
477481
}
@@ -539,13 +543,21 @@ export default class SyncProcess {
539543
mappingsSnapshot
540544
)
541545

546+
// skipErroneousActions: a REORDER targeting a folder that can no longer be mapped is
547+
// moot (the folder was moved/removed); drop it instead of throwing MappingFailureError,
548+
// which would force a cache reset + from-scratch resync that duplicates on non-atomic
549+
// servers.
542550
this.localReorders = localReorders3.map(
543551
mappingsSnapshot,
544-
ItemLocation.LOCAL
552+
ItemLocation.LOCAL,
553+
() => true,
554+
true
545555
)
546556
this.serverReorders = serverReorders3.map(
547557
mappingsSnapshot,
548-
ItemLocation.SERVER
558+
ItemLocation.SERVER,
559+
() => true,
560+
true
549561
)
550562
}
551563

0 commit comments

Comments
 (0)