Skip to content

Commit fdeff70

Browse files
authored
Merge pull request #2109 from floccusaddon/fix/more-mapping-errors
fix: Implement GC for mappings
2 parents 8aab3a7 + 07d5a56 commit fdeff70

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

src/lib/Account.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,10 @@ export default class Account {
312312
}
313313

314314
if (mappings) {
315+
// Remove superfluous items from mappings
316+
// as we don't remove items immediately anymore, due to possible interrupts
317+
await mappings.gc(cache)
318+
// store mappings
315319
await mappings.persist()
316320
}
317321

src/lib/Mappings.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TItem, TItemLocation, TItemType } from './Tree'
1+
import { Folder, ItemLocation, ItemType, TItem, TItemLocation, TItemType } from './Tree'
22

33
type InternalItemTypeMapping = { LocalToServer: Record<string, string>, ServerToLocal: Record<string, string> }
44

@@ -33,6 +33,20 @@ export default class Mappings {
3333
}
3434
}
3535

36+
async gc(tree: Folder<typeof ItemLocation.LOCAL>) {
37+
const index = tree.createIndex()
38+
for (const localId in this.bookmarks.LocalToServer) {
39+
if (!(localId in index[ItemType.BOOKMARK])) {
40+
await this.removeBookmark({localId})
41+
}
42+
}
43+
for (const localId in this.folders.LocalToServer) {
44+
if (!(localId in index[ItemType.FOLDER])) {
45+
await this.removeFolder({localId})
46+
}
47+
}
48+
}
49+
3650
async addFolder({ localId, remoteId }: { localId?:string|number, remoteId?:string|number }):Promise<void> {
3751
Mappings.add(this.folders, { localId, remoteId })
3852
}

src/lib/strategies/Default.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,11 +1381,7 @@ export default class SyncProcess {
13811381
} else {
13821382
localId = item.id
13831383
}
1384-
if (item.type === 'folder') {
1385-
await this.mappings.removeFolder({ localId, remoteId })
1386-
} else {
1387-
await this.mappings.removeBookmark({ localId, remoteId })
1388-
}
1384+
// We don't remove from mappings immediately anymore, but wait for GC
13891385
}
13901386

13911387
async loadChildren(

0 commit comments

Comments
 (0)