Skip to content

Commit e2c846b

Browse files
committed
fix worker, by removing import
1 parent dc6292b commit e2c846b

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

src/lib/workers/parquetWorker.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
11
import type { ColumnData } from 'hyparquet'
2-
import { parquetRead } from 'hyparquet'
2+
import { AsyncBuffer, asyncBufferFromUrl, cachedAsyncBuffer, parquetRead } from 'hyparquet'
33
import { compressors } from 'hyparquet-compressors'
4-
import { asyncBufferFrom } from '../utils.js'
5-
import type { ChunkMessage, ClientMessage, ErrorMessage, ResultMessage } from './types.js'
4+
import type { AsyncBufferFrom, ChunkMessage, ClientMessage, ErrorMessage, ResultMessage } from './types.js'
5+
6+
const cache = new Map<string, Promise<AsyncBuffer>>()
7+
8+
export function asyncBufferFrom(from: AsyncBufferFrom): Promise<AsyncBuffer> {
9+
if ('url' in from) {
10+
// Cached asyncBuffer for urls only
11+
const key = JSON.stringify(from)
12+
const cached = cache.get(key)
13+
if (cached) return cached
14+
const asyncBuffer = asyncBufferFromUrl(from).then(cachedAsyncBuffer)
15+
cache.set(key, asyncBuffer)
16+
return asyncBuffer
17+
} else {
18+
return from.file.arrayBuffer()
19+
}
20+
}
621

722
function postChunkMessage ({ chunk, queryId }: ChunkMessage) {
823
self.postMessage({ chunk, queryId })

src/lib/workers/parquetWorkerClient.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ function getWorker() {
4343
* to be serialized to the worker.
4444
*/
4545
export function parquetQueryWorker({ metadata, from, rowStart, rowEnd, columns, onChunk }: WorkerOptions): Promise<void> {
46-
// TODO(SL) Support passing columns?
4746
return new Promise((resolve, reject) => {
4847
const queryId = nextQueryId++
4948
pending.set(queryId, { resolve, reject, onChunk })

src/lib/workers/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,5 @@ export interface WorkerOptions {
3030
rowEnd?: number,
3131
columns?: string[],
3232
onChunk: (chunk: ColumnData) => void
33-
// TODO(SL): support onPage too?
3433
}
3534
export type ClientMessage = Omit<WorkerOptions, 'onChunk'> & ResultMessage

vite.lib.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const __dirname = dirname (fileURLToPath (import.meta.url ))
99
export default defineConfig({
1010
plugins: [react()],
1111
build: {
12+
minify: true,
1213
outDir: resolve(__dirname, 'lib'),
1314
copyPublicDir: false,
1415
lib: {

0 commit comments

Comments
 (0)