1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-03-26 21:12:59 +02:00

All: Optimise first synchronisation, when items have never been synced before

This commit is contained in:
Laurent Cozic 2021-06-17 11:24:02 +01:00
parent a38958ab7b
commit 15ce5cdd6e
2 changed files with 11 additions and 4 deletions
packages/lib

@ -456,7 +456,7 @@ export default class Synchronizer {
// (by setting an updated_time less than current time).
if (donePaths.indexOf(path) >= 0) throw new JoplinError(sprintf('Processing a path that has already been done: %s. sync_time was not updated? Remote item has an updated_time in the future?', path), 'processingPathTwice');
const remote: RemoteItem = await this.apiCall('stat', path);
const remote: RemoteItem = result.neverSyncedItemIds.includes(local.id) ? null : await this.apiCall('stat', path);
let action = null;
let reason = '';

@ -18,6 +18,12 @@ export interface ItemsThatNeedDecryptionResult {
items: any[];
}
export interface ItemsThatNeedSyncResult {
hasMore: boolean;
items: any[];
neverSyncedItemIds: string[];
}
export default class BaseItem extends BaseModel {
public static encryptionService_: any = null;
@ -583,7 +589,7 @@ export default class BaseItem extends BaseModel {
throw new Error('Unreachable');
}
static async itemsThatNeedSync(syncTarget: number, limit = 100) {
public static async itemsThatNeedSync(syncTarget: number, limit = 100): Promise<ItemsThatNeedSyncResult> {
const classNames = this.syncItemClassNames();
for (let i = 0; i < classNames.length; i++) {
@ -660,12 +666,13 @@ export default class BaseItem extends BaseModel {
changedItems = await ItemClass.modelSelectAll(sql);
}
const neverSyncedItemIds = neverSyncedItem.map((it: any) => it.id);
const items = neverSyncedItem.concat(changedItems);
if (i >= classNames.length - 1) {
return { hasMore: items.length >= limit, items: items };
return { hasMore: items.length >= limit, items: items, neverSyncedItemIds };
} else {
if (items.length) return { hasMore: true, items: items };
if (items.length) return { hasMore: true, items: items, neverSyncedItemIds };
}
}