Skip to content

Commit a0ffbb8

Browse files
authored
Merge pull request #2335 from floccusaddon/fix/avoid-caching-tree-wrapper-collisions
fix(CachingTreeWrapper): Avoid collisions between Chromium IDs and CachingAdapter IDs
2 parents 4851954 + 57e0f7b commit a0ffbb8

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

‎src/lib/CacheTree.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,8 @@ export default class CacheTree extends CachingAdapter implements IResource<typeo
4343
isAvailable(): Promise<boolean> {
4444
return Promise.resolve(true)
4545
}
46+
47+
setHighestId(id: number) {
48+
this.highestId = Math.max(this.highestId, id)
49+
}
4650
}

‎src/lib/CachingTreeWrapper.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ export default class CachingTreeWrapper implements OrderFolderResource<typeof It
2424

2525
async createBookmark(bookmark:Bookmark<typeof ItemLocation.LOCAL>): Promise<string|number> {
2626
const id = await this.innerTree.createBookmark(bookmark)
27+
// In case the browser uses positive int IDs, we need to reset the highestId counter here
28+
// to avoid collisions with the cache tree's auto-generated IDs
29+
this.cacheTree.setHighestId(Number(id) || 0)
2730
const cacheId = await this.cacheTree.createBookmark(bookmark.copy(false))
2831
const cacheBookmark = this.cacheTree.bookmarksCache.findBookmark(cacheId)
2932
this.cacheTree.bookmarksCache.removeFromIndex(cacheBookmark)
@@ -46,6 +49,9 @@ export default class CachingTreeWrapper implements OrderFolderResource<typeof It
4649

4750
async createFolder(folder:Folder<typeof ItemLocation.LOCAL>): Promise<string|number> {
4851
const id = await this.innerTree.createFolder(folder)
52+
// In case the browser uses positive int IDs, we need to reset the highestId counter here
53+
// to avoid collisions with the cache tree's auto-generated IDs
54+
this.cacheTree.setHighestId(Number(id) || 0)
4955
const cacheId = await this.cacheTree.createFolder(folder.copy(false))
5056
const cacheFolder = this.cacheTree.bookmarksCache.findFolder(cacheId)
5157
this.cacheTree.bookmarksCache.removeFromIndex(cacheFolder)

0 commit comments

Comments
 (0)