Fix memory usage by batching syncTasks

This commit is contained in:
Jamie Kyle 2024-12-04 14:03:29 -08:00 committed by GitHub
parent ab1e6f847d
commit 4027f4604f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 154 additions and 75 deletions

View file

@ -4,6 +4,7 @@
import { isNumber, last } from 'lodash';
import type { ReadableDB, WritableDB } from './Interface';
import type { LoggerType } from '../types/Logging';
export type EmptyQuery = [];
export type ArrayQuery = Array<ReadonlyArray<null | number | bigint | string>>;
@ -162,17 +163,6 @@ export function sql(
return [fragment, fragmentParams];
}
type QueryPlanRow = Readonly<{
id: number;
parent: number;
details: string;
}>;
type QueryPlan = Readonly<{
query: string;
plan: ReadonlyArray<QueryPlanRow>;
}>;
/**
* Returns typed objects of the query plan for the given query.
*
@ -189,11 +179,19 @@ type QueryPlan = Readonly<{
*/
export function explainQueryPlan(
db: ReadableDB,
logger: LoggerType,
template: QueryTemplate
): QueryPlan {
): QueryTemplate {
const [query, params] = template;
const plan = db.prepare(`EXPLAIN QUERY PLAN ${query}`).all(params);
return { query, plan };
logger.info('EXPLAIN QUERY PLAN');
for (const line of query.split('\n')) {
logger.info(line);
}
for (const row of plan) {
logger.info(`id=${row.id}, parent=${row.parent}, detail=${row.detail}`);
}
return [query, params];
}
//