@@ -246,8 +246,10 @@ export default class SyncProcess {
246246
247247 Logger . log ( { localPlan : this . localPlanStage2 , serverPlan : this . serverPlanStage2 } )
248248
249- this . applyDeletionFailsafe ( this . localPlanStage2 . REMOVE )
250- this . applyAdditionFailsafe ( this . localPlanStage2 . CREATE )
249+ this . applyDeletionFailsafe ( this . localTreeRoot , this . localPlanStage2 . REMOVE )
250+ this . applyAdditionFailsafe ( this . localTreeRoot , this . localPlanStage2 . CREATE )
251+ this . applyDeletionFailsafe ( this . serverTreeRoot , this . serverPlanStage2 . REMOVE )
252+ this . applyAdditionFailsafe ( this . serverTreeRoot , this . serverPlanStage2 . CREATE )
251253
252254 if ( ! this . localDonePlan ) {
253255 this . localDonePlan = {
@@ -361,30 +363,30 @@ export default class SyncProcess {
361363 this . serverTreeRoot . createIndex ( )
362364 }
363365
364- protected applyDeletionFailsafe ( removals : Diff < TItemLocation , TItemLocation , RemoveAction < TItemLocation , TItemLocation > > ) {
365- const localCountTotal = this . localTreeRoot . count ( )
366- const localCountDeleted = removals . getActions ( ) . reduce ( ( count , action ) => count + action . payload . count ( ) , 0 )
366+ protected applyDeletionFailsafe ( tree : Folder < TItemLocation > , removals : Diff < TItemLocation , TItemLocation , RemoveAction < TItemLocation , TItemLocation > > ) {
367+ const countTotal = tree . count ( )
368+ const countDeleted = removals . getActions ( ) . reduce ( ( count , action ) => count + action . payload . count ( ) , 0 )
367369
368- Logger . log ( 'Checking deletion failsafe: ' + localCountDeleted + '/' + localCountTotal + '=' + ( localCountDeleted / localCountTotal ) )
370+ Logger . log ( 'Checking deletion failsafe: ' + countDeleted + '/' + countTotal + '=' + ( countDeleted / countTotal ) )
369371 // Failsafe kicks in if more than 20% is deleted or more than 1k bookmarks
370- if ( ( localCountTotal > 5 && localCountDeleted / localCountTotal > 0.2 ) || localCountDeleted > 1000 ) {
372+ if ( ( countTotal > 5 && countDeleted / countTotal > 0.2 ) || countDeleted > 1000 ) {
371373 const failsafe = this . server . getData ( ) . failsafe
372374 if ( failsafe !== false || typeof failsafe === 'undefined' ) {
373- throw new DeletionFailsafeError ( Math . ceil ( ( localCountDeleted / localCountTotal ) * 100 ) )
375+ throw new DeletionFailsafeError ( Math . ceil ( ( countDeleted / countTotal ) * 100 ) )
374376 }
375377 }
376378 }
377379
378- protected applyAdditionFailsafe ( creations : Diff < TItemLocation , TItemLocation , CreateAction < TItemLocation , TItemLocation > > ) {
379- const localCountTotal = this . localTreeRoot . count ( )
380- const localCountAdded = creations . getActions ( ) . reduce ( ( count , action ) => count + action . payload . count ( ) , 0 )
380+ protected applyAdditionFailsafe ( tree : Folder < TItemLocation > , creations : Diff < TItemLocation , TItemLocation , CreateAction < TItemLocation , TItemLocation > > ) {
381+ const countTotal = tree . count ( )
382+ const countAdded = creations . getActions ( ) . reduce ( ( count , action ) => count + action . payload . count ( ) , 0 )
381383
382- Logger . log ( 'Checking addition failsafe: ' + localCountAdded + '/' + localCountTotal + '=' + ( localCountAdded / localCountTotal ) )
384+ Logger . log ( 'Checking addition failsafe: ' + countAdded + '/' + countTotal + '=' + ( countAdded / countTotal ) )
383385 // Failsafe kicks in if more than 20% is added or more than 1k bookmarks
384- if ( localCountTotal > 5 && ( localCountAdded / localCountTotal > 0.2 || localCountAdded > 1000 ) ) {
386+ if ( countTotal > 5 && ( countAdded / countTotal > 0.2 || countAdded > 1000 ) ) {
385387 const failsafe = this . server . getData ( ) . failsafe
386388 if ( failsafe !== false || typeof failsafe === 'undefined' ) {
387- throw new AdditionFailsafeError ( Math . ceil ( ( localCountAdded / localCountTotal ) * 100 ) )
389+ throw new AdditionFailsafeError ( Math . ceil ( ( countAdded / countTotal ) * 100 ) )
388390 }
389391 }
390392 }
0 commit comments