diff --git a/src/reporters/site-api.ts b/src/reporters/site-api.ts index b21d7e8..a97cec6 100644 --- a/src/reporters/site-api.ts +++ b/src/reporters/site-api.ts @@ -1,5 +1,5 @@ import * as github from "@actions/github"; -import type { IndexRecommendation } from "@query-doctor/core"; +import type { IndexRecommendation, Nudge } from "@query-doctor/core"; import { DEFAULT_CONFIG, type AnalyzerConfig } from "../config.ts"; import type { QueryProcessResult } from "../runner.ts"; @@ -18,6 +18,7 @@ interface CiQueryPayload { query: string; formattedQuery: string; optimization: CiOptimization; + nudges: Nudge[]; } type CiOptimization = @@ -76,6 +77,7 @@ function mapResultToQuery(result: QueryProcessResult): CiQueryPayload | null { hash: result.recommendation.fingerprint, query: result.rawQuery, formattedQuery: result.recommendation.formattedQuery, + nudges: result.nudges, optimization: { state: "improvements_available", cost: result.recommendation.baseCost, @@ -96,6 +98,7 @@ function mapResultToQuery(result: QueryProcessResult): CiQueryPayload | null { hash: result.fingerprint, query: result.rawQuery, formattedQuery: result.formattedQuery, + nudges: result.nudges, optimization: { state: "no_improvement_found", cost: result.cost, @@ -108,6 +111,7 @@ function mapResultToQuery(result: QueryProcessResult): CiQueryPayload | null { hash: result.fingerprint, query: result.rawQuery, formattedQuery: result.formattedQuery, + nudges: result.nudges, optimization: { state: "no_improvement_found", cost: 0, @@ -120,6 +124,7 @@ function mapResultToQuery(result: QueryProcessResult): CiQueryPayload | null { hash: result.fingerprint, query: result.rawQuery, formattedQuery: result.formattedQuery, + nudges: result.nudges, optimization: { state: "error", error: result.error.message, @@ -131,6 +136,7 @@ function mapResultToQuery(result: QueryProcessResult): CiQueryPayload | null { hash: result.warning.fingerprint, query: result.rawQuery, formattedQuery: result.warning.formattedQuery, + nudges: result.nudges, optimization: result.warning.optimization ? { state: "no_improvement_found", diff --git a/src/runner.ts b/src/runner.ts index 116e684..3485703 100644 --- a/src/runner.ts +++ b/src/runner.ts @@ -13,6 +13,7 @@ import { IndexedTable, IndexOptimizer, type IndexRecommendation, + type Nudge, OptimizeResult, type Postgres, PostgresQueryBuilder, @@ -235,7 +236,7 @@ export class Runner { const analyzer = new Analyzer(parse); const formattedQuery = await this.formatQuery(query); - const { indexesToCheck, ansiHighlightedQuery, referencedTables } = + const { indexesToCheck, ansiHighlightedQuery, referencedTables, nudges } = await analyzer.analyze(formattedQuery); const selectsCatalog = referencedTables.find((ref) => @@ -265,6 +266,7 @@ export class Runner { return { kind: "cost_past_threshold", rawQuery: query, + nudges, warning: { fingerprint: queryFingerprint, formattedQuery, @@ -300,6 +302,7 @@ export class Runner { fingerprint: queryFingerprint, rawQuery: query, formattedQuery, + nudges, }; } if (out.kind === "ok") { @@ -325,6 +328,7 @@ export class Runner { return { kind: "recommendation", rawQuery: query, + nudges, indexRecommendations: newIndexRecommendations, recommendation: { fingerprint: queryFingerprint, @@ -351,6 +355,7 @@ export class Runner { return { kind: "cost_past_threshold", rawQuery: query, + nudges, warning: { fingerprint: queryFingerprint, formattedQuery, @@ -372,6 +377,7 @@ export class Runner { formattedQuery, cost: out.baseCost, existingIndexes: existingIndexesForQuery, + nudges, }; } } else if (out.kind === "zero_cost_plan") { @@ -384,6 +390,7 @@ export class Runner { fingerprint: queryFingerprint, rawQuery: query, formattedQuery, + nudges, }; } console.timeEnd(`timing`); @@ -437,11 +444,13 @@ export type QueryProcessResult = | { kind: "cost_past_threshold"; rawQuery: string; + nudges: Nudge[]; warning: ReportQueryCostWarning; } | { kind: "recommendation"; rawQuery: string; + nudges: Nudge[]; indexRecommendations: IndexRecommendation[]; recommendation: ReportIndexRecommendation; } @@ -452,6 +461,7 @@ export type QueryProcessResult = formattedQuery: string; cost: number; existingIndexes: string[]; + nudges: Nudge[]; } | { kind: "error"; @@ -459,6 +469,7 @@ export type QueryProcessResult = fingerprint: string; rawQuery: string; formattedQuery: string; + nudges: Nudge[]; } | { kind: "zero_cost_plan"; @@ -466,4 +477,5 @@ export type QueryProcessResult = fingerprint: string; rawQuery: string; formattedQuery: string; + nudges: Nudge[]; };