Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/sql/recent-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
type TableReference,
} from "@query-doctor/core";
import { parse } from "@libpg-query/parser";
import { Sema } from "async-sema";
import z from "zod";
import type { LiveQueryOptimization } from "../remote/optimization.ts";

Expand All @@ -21,6 +22,7 @@ import type { LiveQueryOptimization } from "../remote/optimization.ts";
export class RecentQuery {
private static HARDCODED_LIMIT = 50;
private static rewriter = new PssRewriter();
private static prettierMutex = new Sema(1);

readonly formattedQuery: string;
readonly username: string;
Expand Down Expand Up @@ -134,6 +136,7 @@ export class RecentQuery {
}

private static async formatQuery(query: string): Promise<string> {
await RecentQuery.prettierMutex.acquire();
try {
return await prettier.format(query, {
parser: "sql",
Expand All @@ -143,6 +146,8 @@ export class RecentQuery {
});
} catch {
return query;
} finally {
RecentQuery.prettierMutex.release();
}
}

Expand Down
Loading