Skip to content

Commit 2c23b2f

Browse files
committed
[native] fix: Properly serialize cache
to avoid JSON.stringify recursion error Signed-off-by: Marcel Klehr <mklehr@gmx.net>
1 parent 1fe83ae commit 2c23b2f

File tree

4 files changed

+5
-3
lines changed

4 files changed

+5
-3
lines changed

src/lib/Account.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ export default class Account {
331331
Logger.log('Storing cache')
332332
const cache = (await this.localCachingResource.getCacheTree()).clone(false)
333333
this.syncProcess.filterOutUnacceptedBookmarks(cache)
334-
await this.storage.setCache(cache)
334+
await this.storage.setCache(await cache.toJSONAsync())
335335

336336
if (this.server.onSyncComplete) {
337337
Logger.log('Calling onSyncComplete')

src/lib/Tree.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ export class Bookmark<L extends TItemLocation> {
169169
let obj = this
170170
while (obj instanceof Bookmark) {
171171
Object.entries(obj).forEach(([key, value]) => {
172+
if (key === 'index') return
172173
if (!(key in result)) {
173174
result[key] = value
174175
}
@@ -186,6 +187,7 @@ export class Bookmark<L extends TItemLocation> {
186187
while (obj instanceof Bookmark) {
187188
await yieldToEventLoop()
188189
Object.entries(obj).forEach(([key, value]) => {
190+
if (key === 'index') return
189191
if (!(key in result)) {
190192
result[key] = value
191193
}

src/lib/native/NativeAccountStorage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export default class NativeAccountStorage {
114114
async setCache(data) {
115115
await NativeAccountStorage.changeEntry(
116116
`bookmarks[${this.accountId}].cache`,
117-
() => data
117+
() => data.toJSON ? data.toJSON() : data
118118
)
119119
}
120120

src/lib/native/NativeTree.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export default class NativeTree extends CachingAdapter implements BulkImportReso
3434
}
3535

3636
async save():Promise<void> {
37-
await Storage.set({key: `bookmarks[${this.accountId}].tree`, value: JSON.stringify(this.bookmarksCache.cloneWithLocation(true, ItemLocation.LOCAL))})
37+
await Storage.set({key: `bookmarks[${this.accountId}].tree`, value: JSON.stringify(await this.bookmarksCache.cloneWithLocation(true, ItemLocation.LOCAL).toJSONAsync())})
3838
await Storage.set({key: `bookmarks[${this.accountId}].highestId`, value: this.highestId + ''})
3939
}
4040

0 commit comments

Comments
 (0)