mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-18 17:22:45 -05:00
Adding caching to execution plan and refactoring code and some other fixes (#18913)
* Making ep code modular for easy swithcing in and out * Changing to innerText * Fixing renames * Fixing var name in one file
This commit is contained in:
@@ -0,0 +1,117 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import type * as azdata from 'azdata';
|
||||
import * as DOM from 'vs/base/browser/dom';
|
||||
import { localize } from 'vs/nls';
|
||||
import { openNewQuery } from 'sql/workbench/contrib/query/browser/queryActions';
|
||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { RunQueryOnConnectionMode } from 'sql/platform/connection/common/connectionManagement';
|
||||
import { Button } from 'sql/base/browser/ui/button/button';
|
||||
import { removeLineBreaks } from 'sql/base/common/strings';
|
||||
|
||||
export class ExecutionPlanViewHeader {
|
||||
|
||||
private _graphIndex: number; // Index of the graph in the view
|
||||
private _relativeCost: number; // Relative cost of the graph to the script
|
||||
private _graphIndexAndCostContainer: HTMLElement; //Container that holds the graph index and relative cost
|
||||
|
||||
|
||||
private _query: string;
|
||||
private _queryContainer: HTMLElement; // container that holds query text
|
||||
|
||||
private _recommendations: azdata.executionPlan.ExecutionPlanRecommendations[];
|
||||
private _recommendationsContainer: HTMLElement; // container that holds graph recommendations
|
||||
|
||||
public constructor(
|
||||
private _parentContainer: HTMLElement,
|
||||
headerData: PlanHeaderData,
|
||||
@IInstantiationService public readonly _instantiationService: IInstantiationService) {
|
||||
|
||||
this._graphIndex = headerData.planIndex;
|
||||
this._relativeCost = headerData.relativeCost;
|
||||
this._query = headerData.query;
|
||||
this._recommendations = headerData.recommendations ?? [];
|
||||
|
||||
this._graphIndexAndCostContainer = DOM.$('.index-row');
|
||||
this._queryContainer = DOM.$('.query-row');
|
||||
this._recommendationsContainer = DOM.$('.recommendations');
|
||||
|
||||
this._parentContainer.appendChild(this._graphIndexAndCostContainer);
|
||||
this._parentContainer.appendChild(this._queryContainer);
|
||||
this._parentContainer.appendChild(this._recommendationsContainer);
|
||||
|
||||
this.renderGraphIndexAndCost();
|
||||
this.renderQueryText();
|
||||
this.renderRecommendations();
|
||||
}
|
||||
|
||||
public set graphIndex(index: number) {
|
||||
this._graphIndex = index;
|
||||
this.renderGraphIndexAndCost();
|
||||
}
|
||||
public set relativeCost(cost: number) {
|
||||
this._relativeCost = cost;
|
||||
this.renderGraphIndexAndCost();
|
||||
}
|
||||
public set query(query: string) {
|
||||
this._query = removeLineBreaks(query, ' ');
|
||||
this.renderQueryText();
|
||||
}
|
||||
|
||||
public set recommendations(recommendations: azdata.executionPlan.ExecutionPlanRecommendations[]) {
|
||||
recommendations.forEach(r => {
|
||||
r.displayString = removeLineBreaks(r.displayString);
|
||||
});
|
||||
this._recommendations = recommendations;
|
||||
this.renderRecommendations();
|
||||
}
|
||||
|
||||
private renderGraphIndexAndCost(): void {
|
||||
if (this._graphIndex && this._relativeCost) {
|
||||
this._graphIndexAndCostContainer.innerText = localize(
|
||||
{
|
||||
key: 'planHeaderIndexAndCost',
|
||||
comment: [
|
||||
'{0} is the index of the graph in the execution plan tab',
|
||||
'{1} is the relative cost in percentage of the graph to the rest of the graphs in execution plan tab '
|
||||
]
|
||||
},
|
||||
"Query {0}: Query cost (relative to the script): {1}%", this._graphIndex, this._relativeCost.toFixed(2));
|
||||
}
|
||||
}
|
||||
|
||||
private renderQueryText(): void {
|
||||
this._queryContainer.innerText = this._query;
|
||||
}
|
||||
|
||||
private renderRecommendations(): void {
|
||||
while (this._recommendationsContainer.firstChild) {
|
||||
this._recommendationsContainer.removeChild(this._recommendationsContainer.firstChild);
|
||||
}
|
||||
this._recommendations.forEach(r => {
|
||||
|
||||
const link = new Button(this._recommendationsContainer, {
|
||||
title: r.displayString,
|
||||
secondary: true,
|
||||
});
|
||||
|
||||
link.label = r.displayString;
|
||||
|
||||
//Enabling on click action for recommendations. It will open the recommendation File
|
||||
link.onDidClick(e => {
|
||||
this._instantiationService.invokeFunction(openNewQuery, undefined, r.queryWithDescription, RunQueryOnConnectionMode.none);
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
export interface PlanHeaderData {
|
||||
planIndex?: number;
|
||||
relativeCost?: number;
|
||||
query?: string;
|
||||
recommendations?: azdata.executionPlan.ExecutionPlanRecommendations[];
|
||||
}
|
||||
Reference in New Issue
Block a user