Fix memory usage by batching syncTasks
This commit is contained in:
parent
ab1e6f847d
commit
4027f4604f
8 changed files with 154 additions and 75 deletions
|
@ -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];
|
||||
}
|
||||
|
||||
//
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue