Batch messages on the exthost to not freeze ads (#8949)

* batch messages on the exthost to not freeze ads

* clear out messages on query complete
This commit is contained in:
Anthony Dresser
2020-02-20 14:50:13 -08:00
committed by GitHub
parent 8fe0a13b61
commit 4c54b5dbac
11 changed files with 103 additions and 41 deletions

View File

@@ -142,9 +142,10 @@ export class InsightsDialogController {
this._errorMessageService.showDialog(Severity.Error, nls.localize("insightsError", "Insights error"), error);
});
});
queryRunner.onMessage(message => {
if (message.isError) {
this._errorMessageService.showDialog(Severity.Error, nls.localize("insightsError", "Insights error"), message.message);
queryRunner.onMessage(messages => {
const errorMessage = messages.find(m => m.isError);
if (errorMessage) {
this._errorMessageService.showDialog(Severity.Error, nls.localize("insightsError", "Insights error"), errorMessage.message);
}
});
}

View File

@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import { InsightsDialogController } from 'sql/workbench/services/insights/browser/insightsDialogController';
import QueryRunner from 'sql/workbench/services/query/common/queryRunner';
import QueryRunner, { IQueryMessage } from 'sql/workbench/services/query/common/queryRunner';
import { ConnectionManagementService } from 'sql/workbench/services/connection/browser/connectionManagementService';
import { IConnectionProfile } from 'sql/platform/connection/common/interfaces';
@@ -112,7 +112,7 @@ function getPrimedQueryRunner(data: string[][], columns: string[]): IPrimedQuery
const emitter = new Emitter<string>();
const querymock = Mock.ofType(QueryRunner, MockBehavior.Strict);
querymock.setup(x => x.onQueryEnd).returns(x => emitter.event);
querymock.setup(x => x.onMessage).returns(x => new Emitter<azdata.IResultMessage>().event);
querymock.setup(x => x.onMessage).returns(x => new Emitter<[IQueryMessage]>().event);
querymock.setup(x => x.batchSets).returns(x => {
return <Array<azdata.BatchSummary>>[
{

View File

@@ -340,10 +340,12 @@ class SqlKernel extends Disposable implements nb.IKernel {
this._errorMessageService.showDialog(Severity.Error, sqlKernelError, error);
});
}));
this._register(queryRunner.onMessage(message => {
this._register(queryRunner.onMessage(messages => {
// TODO handle showing a messages output (should be updated with all messages, only changing 1 output in total)
if (this._future && isUndefinedOrNull(message.selection)) {
this._future.handleMessage(message);
for (const message of messages) {
if (this._future && isUndefinedOrNull(message.selection)) {
this._future.handleMessage(message);
}
}
}));
this._register(queryRunner.onBatchEnd(batch => {

View File

@@ -45,7 +45,7 @@ export interface IQueryManagementService {
onBatchComplete(batchInfo: azdata.QueryExecuteBatchNotificationParams): void;
onResultSetAvailable(resultSetInfo: azdata.QueryExecuteResultSetNotificationParams): void;
onResultSetUpdated(resultSetInfo: azdata.QueryExecuteResultSetNotificationParams): void;
onMessage(message: azdata.QueryExecuteMessageParams): void;
onMessage(message: Map<string, azdata.QueryExecuteMessageParams[]>): void;
// Edit Data Callbacks
onEditSessionReady(ownerUri: string, success: boolean, message: string): void;
@@ -283,10 +283,12 @@ export class QueryManagementService implements IQueryManagementService {
});
}
public onMessage(message: azdata.QueryExecuteMessageParams): void {
this._notify(message.ownerUri, (runner: QueryRunner) => {
runner.handleMessage(message);
});
public onMessage(messagesMap: Map<string, azdata.QueryExecuteMessageParams[]>): void {
for (const [uri, messages] of messagesMap) {
this._notify(uri, (runner: QueryRunner) => {
runner.handleMessage(messages);
});
}
}
// Edit Data Functions

View File

@@ -34,7 +34,11 @@ export interface IEditSessionReadyEvent {
message: string;
}
export interface IQueryMessage extends azdata.IResultMessage {
export interface IQueryMessage {
batchId?: number;
isError: boolean;
time?: string;
message: string;
selection?: azdata.ISelectionData;
}
@@ -58,8 +62,8 @@ export default class QueryRunner extends Disposable {
private _planXml = new Deferred<string>();
public get planXml(): Promise<string> { return this._planXml.promise; }
private _onMessage = this._register(new Emitter<IQueryMessage>());
public get onMessage(): Event<IQueryMessage> { return this._onMessage.event; } // this is the only way typemoq can moq this... needs investigation @todo anthonydresser 5/2/2019
private _onMessage = this._register(new Emitter<IQueryMessage[]>());
public get onMessage(): Event<IQueryMessage[]> { return this._onMessage.event; } // this is the only way typemoq can moq this... needs investigation @todo anthonydresser 5/2/2019
private _onResultSet = this._register(new Emitter<azdata.ResultSetSummary>());
public readonly onResultSet = this._onResultSet.event;
@@ -225,13 +229,13 @@ export default class QueryRunner extends Disposable {
error = error.message;
}
let message = nls.localize('query.ExecutionFailedError', "Execution failed due to an unexpected error: {0}\t{1}", eol, error);
this.handleMessage(<azdata.QueryExecuteMessageParams>{
this.handleMessage([<azdata.QueryExecuteMessageParams>{
ownerUri: this.uri,
message: {
isError: true,
message: message
}
});
}]);
this.handleQueryComplete(<azdata.QueryExecuteCompleteNotificationResult>{ ownerUri: this.uri });
}
@@ -267,7 +271,7 @@ export default class QueryRunner extends Disposable {
this._messages.push(message);
this._onQueryEnd.fire(timeStamp);
this._onMessage.fire(message);
this._onMessage.fire([message]);
}
/**
@@ -293,12 +297,12 @@ export default class QueryRunner extends Disposable {
let message = {
// account for index by 1
message: nls.localize('query.message.startQuery', "Started executing query at Line {0}", batch.selection.startLine + 1),
time: new Date(batch.executionStart).toLocaleTimeString(),
time: batch.executionStart,
selection: batch.selection,
isError: false
};
this._messages.push(message);
this._onMessage.fire(message);
this._onMessage.fire([message]);
this._onBatchStart.fire(batch);
}
@@ -403,13 +407,12 @@ export default class QueryRunner extends Disposable {
/**
* Handle a Mssage from the service layer
*/
public handleMessage(obj: azdata.QueryExecuteMessageParams): void {
let message = obj.message;
message.time = new Date(message.time!).toLocaleTimeString();
this._messages.push(message);
public handleMessage(messagesObj: azdata.QueryExecuteMessageParams[]): void {
const messages = messagesObj.map(m => m.message);
this._messages.push(...messages);
// Send the message to the results pane
this._onMessage.fire(message);
this._onMessage.fire(messages);
}
/**
@@ -580,7 +583,7 @@ export default class QueryRunner extends Disposable {
};
this._messages.push(message);
// Send the message to the results pane
this._onMessage.fire(message);
this._onMessage.fire([message]);
}
}