1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-11-23 22:36:32 +02:00

All: Avoid excessive data usage when automatically triggering another sync (#13261)

This commit is contained in:
mrjo118
2025-10-10 09:36:42 +01:00
committed by GitHub
parent b35d9a64cf
commit 8ee46bb4e7
4 changed files with 21 additions and 7 deletions

View File

@@ -32,6 +32,7 @@ import syncDeleteStep from './services/synchronizer/utils/syncDeleteStep';
import { ErrorCode } from './errors';
import { SyncAction } from './services/synchronizer/utils/types';
import checkDisabledSyncItemsNotification from './services/synchronizer/utils/checkDisabledSyncItemsNotification';
import { reg } from './registry';
import SyncTargetRegistry from './SyncTargetRegistry';
const { sprintf } = require('sprintf-js');
const { Dirnames } = require('./services/synchronizer/utils/types');
@@ -388,7 +389,7 @@ export default class Synchronizer {
// 2. DELETE_REMOTE: Delete on the sync target, the items that have been deleted locally.
// 3. DELTA: Find on the sync target the items that have been modified or deleted and apply the changes locally.
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
public async start(options: any = null): Promise<any> {
public async start(options: any = null) {
if (!options) options = {};
if (this.state() !== 'idle') {
@@ -629,7 +630,7 @@ export default class Synchronizer {
} else if (syncItem.force_sync) {
throw new JoplinError(sprintf('Processing a path that has already been done: %s. Item was marked for sync using force_sync', path), 'processingPathTwice');
} else {
logger.info(sprintf('Processing a path that has already been done: %s. The user is making changes while the sync is in progress', path));
throw new JoplinError(sprintf('Processing a path that has already been done: %s. The user is making changes while the sync is in progress', path), 'changedDuringSync');
}
}
@@ -1161,6 +1162,10 @@ export default class Synchronizer {
} else if (error.code === 'unknownItemType') {
this.progressReport_.errors.push(_('Unknown item type downloaded - please upgrade Joplin to the latest version'));
logger.error(error);
} else if (error.code === 'changedDuringSync') {
// We want to re-trigger the sync in this scenario
hasCaughtError = false;
logger.info(error.message);
} else {
logger.error(error);
if (error.details) logger.error('Details:', error.details);
@@ -1222,11 +1227,10 @@ export default class Synchronizer {
// IMPORTANT: This must be the very last step in the sync, to avoid any window to allow an un-synced change to get missed
if (!hasErrors && !hasCaughtError && !cancelledBeforeClearedState && !this.cancelling()) {
const result = await BaseItem.itemsThatNeedSync(syncTargetId);
options.context = outputContext;
if (result.items.length > 0) {
logger.info('There are more outgoing changes to sync, trigger the sync again');
return await this.start(options);
logger.info('There are more outgoing changes to sync, schedule the sync again');
void reg.scheduleSync(reg.syncAsYouTypeInterval(), { syncSteps }, true);
}
}