Fix cached AsyncBuffer for urls only

This commit is contained in:
Kenny Daniel 2024-10-16 15:13:36 -07:00
parent 447dab35be
commit 39f8c184a4
No known key found for this signature in database
GPG Key ID: FDF16101AF5AFD3A
5 changed files with 15 additions and 10 deletions

2
demo/bundle.min.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -57,11 +57,16 @@ export function parquetQueryWorker({
* Convert AsyncBufferFrom to AsyncBuffer.
*/
export async function asyncBufferFrom(from: AsyncBufferFrom): Promise<AsyncBuffer> {
const key = JSON.stringify(from)
const cached = cache.get(key)
if (cached) return cached
const asyncBuffer = 'url' in from ? asyncBufferFromUrl(from.url, from.byteLength) : from.file.arrayBuffer()
cache.set(key, asyncBuffer.then(cachedAsyncBuffer))
return asyncBuffer
if ('url' in from) {
// Cached asyncBuffer for urls only
const key = JSON.stringify(from)
const cached = cache.get(key)
if (cached) return cached
const asyncBuffer = asyncBufferFromUrl(from.url, from.byteLength).then(cachedAsyncBuffer)
cache.set(key, asyncBuffer)
return asyncBuffer
} else {
return from.file.arrayBuffer()
}
}
const cache = new Map<string, Promise<AsyncBuffer>>()

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long