You've already forked joplin
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:
@@ -144,7 +144,7 @@ const generalMiddleware = (store: any) => (next: any) => async (action: any) =>
|
|||||||
if (action.type === 'NAV_GO') Keyboard.dismiss();
|
if (action.type === 'NAV_GO') Keyboard.dismiss();
|
||||||
|
|
||||||
if (['NOTE_UPDATE_ONE', 'NOTE_DELETE', 'FOLDER_UPDATE_ONE', 'FOLDER_DELETE'].indexOf(action.type) >= 0) {
|
if (['NOTE_UPDATE_ONE', 'NOTE_DELETE', 'FOLDER_UPDATE_ONE', 'FOLDER_DELETE'].indexOf(action.type) >= 0) {
|
||||||
if (!await reg.syncTarget().syncStarted()) void reg.scheduleSync(1000, { syncSteps: ['update_remote', 'delete_remote'] }, true);
|
if (!await reg.syncTarget().syncStarted()) void reg.scheduleSync(reg.syncAsYouTypeInterval(), { syncSteps: ['update_remote', 'delete_remote'] }, true);
|
||||||
SearchEngine.instance().scheduleSyncTables();
|
SearchEngine.instance().scheduleSyncTables();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -451,7 +451,7 @@ export default class BaseApplication {
|
|||||||
const newState = store.getState() as State;
|
const newState = store.getState() as State;
|
||||||
|
|
||||||
if (this.hasGui() && ['NOTE_UPDATE_ONE', 'NOTE_DELETE', 'FOLDER_UPDATE_ONE', 'FOLDER_DELETE'].indexOf(action.type) >= 0) {
|
if (this.hasGui() && ['NOTE_UPDATE_ONE', 'NOTE_DELETE', 'FOLDER_UPDATE_ONE', 'FOLDER_DELETE'].indexOf(action.type) >= 0) {
|
||||||
if (!(await reg.syncTarget().syncStarted())) void reg.scheduleSync(15 * 1000, { syncSteps: ['update_remote', 'delete_remote'] });
|
if (!(await reg.syncTarget().syncStarted())) void reg.scheduleSync(reg.syncAsYouTypeInterval(), { syncSteps: ['update_remote', 'delete_remote'] });
|
||||||
SearchEngine.instance().scheduleSyncTables();
|
SearchEngine.instance().scheduleSyncTables();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import syncDeleteStep from './services/synchronizer/utils/syncDeleteStep';
|
|||||||
import { ErrorCode } from './errors';
|
import { ErrorCode } from './errors';
|
||||||
import { SyncAction } from './services/synchronizer/utils/types';
|
import { SyncAction } from './services/synchronizer/utils/types';
|
||||||
import checkDisabledSyncItemsNotification from './services/synchronizer/utils/checkDisabledSyncItemsNotification';
|
import checkDisabledSyncItemsNotification from './services/synchronizer/utils/checkDisabledSyncItemsNotification';
|
||||||
|
import { reg } from './registry';
|
||||||
import SyncTargetRegistry from './SyncTargetRegistry';
|
import SyncTargetRegistry from './SyncTargetRegistry';
|
||||||
const { sprintf } = require('sprintf-js');
|
const { sprintf } = require('sprintf-js');
|
||||||
const { Dirnames } = require('./services/synchronizer/utils/types');
|
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.
|
// 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.
|
// 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
|
// 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 (!options) options = {};
|
||||||
|
|
||||||
if (this.state() !== 'idle') {
|
if (this.state() !== 'idle') {
|
||||||
@@ -629,7 +630,7 @@ export default class Synchronizer {
|
|||||||
} else if (syncItem.force_sync) {
|
} 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');
|
throw new JoplinError(sprintf('Processing a path that has already been done: %s. Item was marked for sync using force_sync', path), 'processingPathTwice');
|
||||||
} else {
|
} 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') {
|
} else if (error.code === 'unknownItemType') {
|
||||||
this.progressReport_.errors.push(_('Unknown item type downloaded - please upgrade Joplin to the latest version'));
|
this.progressReport_.errors.push(_('Unknown item type downloaded - please upgrade Joplin to the latest version'));
|
||||||
logger.error(error);
|
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 {
|
} else {
|
||||||
logger.error(error);
|
logger.error(error);
|
||||||
if (error.details) logger.error('Details:', error.details);
|
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
|
// 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()) {
|
if (!hasErrors && !hasCaughtError && !cancelledBeforeClearedState && !this.cancelling()) {
|
||||||
const result = await BaseItem.itemsThatNeedSync(syncTargetId);
|
const result = await BaseItem.itemsThatNeedSync(syncTargetId);
|
||||||
options.context = outputContext;
|
|
||||||
|
|
||||||
if (result.items.length > 0) {
|
if (result.items.length > 0) {
|
||||||
logger.info('There are more outgoing changes to sync, trigger the sync again');
|
logger.info('There are more outgoing changes to sync, schedule the sync again');
|
||||||
return await this.start(options);
|
void reg.scheduleSync(reg.syncAsYouTypeInterval(), { syncSteps }, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -70,6 +70,16 @@ class Registry {
|
|||||||
return this.syncTarget(SyncTargetRegistry.nameToId('nextcloud'));
|
return this.syncTarget(SyncTargetRegistry.nameToId('nextcloud'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// There is a delay of at least 1 second to avoid using excessive data usage, as the full note contents are uploaded every time a change is made.
|
||||||
|
// On desktop this delay is longer, to avoid distraction to the user due to the sync button continually stopping and starting spinning
|
||||||
|
public syncAsYouTypeInterval() {
|
||||||
|
if (shim.isElectron()) {
|
||||||
|
return 15 * 1000;
|
||||||
|
} else {
|
||||||
|
return 1000;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public syncTarget = (syncTargetId: number = null) => {
|
public syncTarget = (syncTargetId: number = null) => {
|
||||||
if (syncTargetId === null) syncTargetId = Setting.value('sync.target');
|
if (syncTargetId === null) syncTargetId = Setting.value('sync.target');
|
||||||
if (this.syncTargets_[syncTargetId]) return this.syncTargets_[syncTargetId];
|
if (this.syncTargets_[syncTargetId]) return this.syncTargets_[syncTargetId];
|
||||||
|
|||||||
Reference in New Issue
Block a user