From a58c3f385dd73156041d991f3da9bc94263a7b02 Mon Sep 17 00:00:00 2001 From: ecmel Date: Thu, 26 Dec 2024 09:36:55 +0300 Subject: [PATCH 1/3] unified query progress --- src/classes/insightsConnection.ts | 8 ++-- src/commands/dataSourceCommand.ts | 4 +- src/commands/serverCommand.ts | 61 +++++++++++++++++++++++++------ 3 files changed, 55 insertions(+), 18 deletions(-) diff --git a/src/classes/insightsConnection.ts b/src/classes/insightsConnection.ts index f740b528..31ac8742 100644 --- a/src/classes/insightsConnection.ts +++ b/src/classes/insightsConnection.ts @@ -403,9 +403,6 @@ export class InsightsConnection { ): Promise { if (this.connected && this.connEndpoints) { const isTableView = ext.isResultsTabVisible; - const queryMsg = isStarting - ? "Starting scratchpad..." - : "Query is executing..."; const scratchpadURL = new url.URL( this.connEndpoints.scratchpad.scratchpad, this.node.details.server, @@ -456,7 +453,10 @@ export class InsightsConnection { kdbOutputLog(`User cancelled the Scrathpad execution.`, "WARNING"); }); - progress.report({ message: queryMsg }); + if (isStarting) { + progress.report({ message: "Starting scratchpad..." }); + } + const spRes = await axios .post(scratchpadURL.toString(), body, { headers, diff --git a/src/commands/dataSourceCommand.ts b/src/commands/dataSourceCommand.ts index c01f21f5..9236256e 100644 --- a/src/commands/dataSourceCommand.ts +++ b/src/commands/dataSourceCommand.ts @@ -170,7 +170,7 @@ export async function runDataSource( const resultCount = typeof res === "string" ? "0" : res.rows.length; kdbOutputLog(`[DATASOURCE] Results: ${resultCount} rows`, "INFO"); } - writeQueryResultsToView( + await writeQueryResultsToView( success ? res : res.error, query, connLabel, @@ -185,7 +185,7 @@ export async function runDataSource( "INFO", ); } - writeQueryResultsToConsole( + await writeQueryResultsToConsole( success ? res : res.error, query, connLabel, diff --git a/src/commands/serverCommand.ts b/src/commands/serverCommand.ts index 09a7a6f0..c6cb2181 100644 --- a/src/commands/serverCommand.ts +++ b/src/commands/serverCommand.ts @@ -15,7 +15,9 @@ import { readFileSync } from "fs-extra"; import { join } from "path"; import * as url from "url"; import { + CancellationToken, Position, + ProgressLocation, Range, Uri, ViewColumn, @@ -790,6 +792,37 @@ export async function executeQuery( isPython: boolean, isWorkbook: boolean, isFromConnTree?: boolean, +): Promise { + await window.withProgress( + { + cancellable: true, + location: ProgressLocation.Window, + title: `Executing Query (${executorName})`, + }, + async (_progress, token) => { + await _executeQuery( + query, + connLabel, + executorName, + context, + isPython, + isWorkbook, + isFromConnTree, + token, + ); + }, + ); +} + +async function _executeQuery( + query: string, + connLabel: string, + executorName: string, + context: string, + isPython: boolean, + isWorkbook: boolean, + isFromConnTree?: boolean, + token?: CancellationToken, ): Promise { const connMngService = new ConnectionManagementService(); const queryConsole = ExecutionConsole.start(); @@ -842,9 +875,13 @@ export async function executeQuery( const endTime = Date.now(); const duration = (endTime - startTime).toString(); + if (token?.isCancellationRequested) { + return undefined; + } + // set context for root nodes if (selectedConn instanceof InsightsConnection) { - writeScratchpadResult( + await writeScratchpadResult( results, query, connLabel, @@ -875,7 +912,7 @@ export async function executeQuery( await setUriContent(uri, JSON.stringify(plot)); } } else if (ext.isResultsTabVisible) { - writeQueryResultsToView( + await writeQueryResultsToView( results, query, connLabel, @@ -888,7 +925,7 @@ export async function executeQuery( connVersion, ); } else { - writeQueryResultsToConsole( + await writeQueryResultsToConsole( results, query, connLabel, @@ -1123,7 +1160,7 @@ export async function exportConnections(connLabel?: string) { } } -export function writeQueryResultsToConsole( +export async function writeQueryResultsToConsole( result: string | string[], query: string, connLabel: string, @@ -1133,7 +1170,7 @@ export function writeQueryResultsToConsole( isPython?: boolean, duration?: string, isFromConnTree?: boolean, -): void { +): Promise { const queryConsole = ExecutionConsole.start(); const isNonEmptyArray = Array.isArray(result) && result.length > 0; const valueToDecode = isNonEmptyArray ? result[0] : result.toString(); @@ -1169,7 +1206,7 @@ export function writeQueryResultsToConsole( } } -export function writeQueryResultsToView( +export async function writeQueryResultsToView( result: any, query: string, connLabel: string, @@ -1180,8 +1217,8 @@ export function writeQueryResultsToView( duration?: string, isFromConnTree?: boolean, connVersion?: number, -): void { - commands.executeCommand( +): Promise { + await commands.executeCommand( "kdb.resultsPanel.update", result, isInsights, @@ -1204,7 +1241,7 @@ export function writeQueryResultsToView( } } -export function writeScratchpadResult( +export async function writeScratchpadResult( result: ScratchpadResult, query: string, connLabel: string, @@ -1213,7 +1250,7 @@ export function writeScratchpadResult( isWorkbook: boolean, duration: string, connVersion: number, -): void { +): Promise { let errorMsg; if (result.error) { @@ -1226,7 +1263,7 @@ export function writeScratchpadResult( } if (ext.isResultsTabVisible) { - writeQueryResultsToView( + await writeQueryResultsToView( errorMsg ?? result, query, connLabel, @@ -1239,7 +1276,7 @@ export function writeScratchpadResult( connVersion, ); } else { - writeQueryResultsToConsole( + await writeQueryResultsToConsole( errorMsg ?? result.data, query, connLabel, From 891ffb869e42e5077161c5655fcc3e35f87bb782 Mon Sep 17 00:00:00 2001 From: ecmel Date: Thu, 26 Dec 2024 09:47:33 +0300 Subject: [PATCH 2/3] fixed coverage --- src/commands/serverCommand.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/commands/serverCommand.ts b/src/commands/serverCommand.ts index c6cb2181..7f5cfb2e 100644 --- a/src/commands/serverCommand.ts +++ b/src/commands/serverCommand.ts @@ -875,6 +875,7 @@ async function _executeQuery( const endTime = Date.now(); const duration = (endTime - startTime).toString(); + /* istanbul ignore next */ if (token?.isCancellationRequested) { return undefined; } From e098c9bbc0cd3070afe177d0c51e05511954f4ba Mon Sep 17 00:00:00 2001 From: ecmel Date: Mon, 30 Dec 2024 14:25:53 +0300 Subject: [PATCH 3/3] fixed typos --- src/classes/insightsConnection.ts | 2 +- src/commands/serverCommand.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/classes/insightsConnection.ts b/src/classes/insightsConnection.ts index 31ac8742..7908b0e3 100644 --- a/src/classes/insightsConnection.ts +++ b/src/classes/insightsConnection.ts @@ -450,7 +450,7 @@ export class InsightsConnection { }, async (progress, token) => { token.onCancellationRequested(() => { - kdbOutputLog(`User cancelled the Scrathpad execution.`, "WARNING"); + kdbOutputLog(`User cancelled the scratchpad execution.`, "WARNING"); }); if (isStarting) { diff --git a/src/commands/serverCommand.ts b/src/commands/serverCommand.ts index 7f5cfb2e..ae632b42 100644 --- a/src/commands/serverCommand.ts +++ b/src/commands/serverCommand.ts @@ -797,7 +797,7 @@ export async function executeQuery( { cancellable: true, location: ProgressLocation.Window, - title: `Executing Query (${executorName})`, + title: `Executing query (${executorName})`, }, async (_progress, token) => { await _executeQuery(