Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/lib/CacheTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,8 @@ export default class CacheTree extends CachingAdapter implements IResource<typeo
isAvailable(): Promise<boolean> {
return Promise.resolve(true)
}

setHighestId(id: number) {
this.highestId = Math.max(this.highestId, id)
}
}
6 changes: 6 additions & 0 deletions src/lib/CachingTreeWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ export default class CachingTreeWrapper implements OrderFolderResource<typeof It

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

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