Serialize sql args/results

Co-authored-by: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com>
This commit is contained in:
automated-signal
2026-03-24 17:40:12 -05:00
committed by GitHub
parent 5fb2d59449
commit cd979c031a
4 changed files with 98 additions and 29 deletions

View File

@@ -2,6 +2,7 @@
// SPDX-License-Identifier: AGPL-3.0-only
import { parentPort } from 'node:worker_threads';
import { serialize, deserialize } from 'node:v8';
import type {
WrappedWorkerRequest,
@@ -109,11 +110,17 @@ const onMessage = (
throw new Error(`Invalid sql method: ${request.method} ${method}`);
}
const start = performance.now();
const result = method(db, ...request.args);
const end = performance.now();
const args =
request.encoding === 'js' ? request.args : deserialize(request.data);
respond(seq, { result, duration: end - start });
const start = performance.now();
const result = method(db, ...args);
const duration = performance.now() - start;
respond(seq, {
result: request.encoding === 'js' ? result : serialize(result),
duration,
});
} else {
throw new Error('Unexpected request type');
}