Skip to content

Commit

Permalink
cache on load
Browse files Browse the repository at this point in the history
  • Loading branch information
jchris committed Jun 13, 2024
1 parent 9b754ae commit beb3e5d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions packages/encrypted-blockstore/src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ export class Loader implements Loadable {
)
: await encodeCarFile([cidRootBlock.cid], clonedt)
carFiles.push(carFile)
// console.log("split to ", carFiles.length, "files")
console.log("split to ", carFiles.length, "files")
return carFiles
}

Expand Down Expand Up @@ -543,7 +543,12 @@ export class Loader implements Loadable {
const readerP = publicFiles
? Promise.resolve(rawReader)
: this.ensureDecryptedReader(rawReader)
this.carReaders.set(cidsString, readerP)

const cachedReaderP = readerP.then(async (reader) => {
await this.cacheCarReader(cidsString, reader).catch((e) => {})
return reader
})
this.carReaders.set(cidsString, cachedReaderP)
return readerP
})().catch((e) => {
this.carReaders.delete(cidsString)
Expand Down
4 changes: 2 additions & 2 deletions packages/fireproof/test/www/todo.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
input.value = dbName
} else {
dbName = name
db = fireproof(name, { autoCompact: 100 })
cx = connect.partykit(db)
db = fireproof(name, { autoCompact: 100, threshold: 50000 })
cx = connect.partykitRest(db)
cx.ready.then(async () => {
const span = document.querySelector('#cxInfo')
span.innerText = `📡 ${cx.party.id}`
Expand Down

0 comments on commit beb3e5d

Please sign in to comment.