fix(Unidirectional): Scanner should use mappings if possible

Signed-off-by: Marcel Klehr <mklehr@gmx.net>
This commit is contained in:
Marcel Klehr 2024-05-09 11:33:55 +02:00
Родитель aabcf73fc4
Коммит 9b6ac3e856
2 изменённых файлов: 37 добавлений и 2 удалений

Просмотреть файл

@ -370,7 +370,7 @@ export default class SyncProcess {
this.serverTreeRoot,
// We also allow canMergeWith here, because e.g. for NextcloudFolders the id of moved bookmarks changes (because their id is "<bookmarkID>;<folderId>")
(oldItem, newItem) => {
if ((oldItem.type === newItem.type && String(mappingsSnapshot.LocalToServer[oldItem.type][oldItem.id]) === String(newItem.id)) || (oldItem.type === 'bookmark' && oldItem.canMergeWith(newItem))) {
if ((oldItem.type === newItem.type && Mappings.mappable(mappingsSnapshot, oldItem, newItem)) || (oldItem.type === 'bookmark' && oldItem.canMergeWith(newItem))) {
newMappings.push([oldItem, newItem])
return true
}

Просмотреть файл

@ -7,6 +7,7 @@ import Logger from '../Logger'
import { CancelledSyncError } from '../../errors/Error'
import MergeSyncProcess from './Merge'
import TResource, { IResource, OrderFolderResource } from '../interfaces/Resource'
import Scanner from '../Scanner'
export default class UnidirectionalSyncProcess extends DefaultStrategy {
protected direction: TItemLocation
@ -20,7 +21,41 @@ export default class UnidirectionalSyncProcess extends DefaultStrategy {
}
async getDiffs():Promise<{localDiff:Diff, serverDiff:Diff}> {
return MergeSyncProcess.prototype.getDiffs.apply(this) // cheeky!
const mappingsSnapshot = this.mappings.getSnapshot()
const newMappings = []
const localScanner = new Scanner(
this.serverTreeRoot,
this.localTreeRoot,
(serverItem, localItem) => {
if (localItem.type === serverItem.type && (serverItem.canMergeWith(localItem) || Mappings.mappable(mappingsSnapshot, serverItem, localItem))) {
newMappings.push([localItem, serverItem])
return true
}
return false
},
this.preserveOrder,
false
)
const serverScanner = new Scanner(
this.localTreeRoot,
this.serverTreeRoot,
(localItem, serverItem) => {
if (serverItem.type === localItem.type && (serverItem.canMergeWith(localItem) || Mappings.mappable(mappingsSnapshot, serverItem, localItem))) {
newMappings.push([localItem, serverItem])
return true
}
return false
},
this.preserveOrder,
false
)
const [localDiff, serverDiff] = await Promise.all([localScanner.run(), serverScanner.run()])
await Promise.all(newMappings.map(([localItem, serverItem]) => {
this.addMapping(this.server, localItem, serverItem.id)
}))
return {localDiff, serverDiff}
}
async loadChildren() :Promise<void> {