Query Editor Memory improvements (#3041)

* working through memory issues

* work in progress

* add missing value

* work in progress

* more work in progress

* various more memory fixes

* additional improvements

* fix imports

* change test that we dispose queries on close not dispose

* update tests
This commit is contained in:
Anthony Dresser
2018-11-05 16:08:41 -08:00
committed by GitHub
parent 399d6d0045
commit 5f2e17a738
22 changed files with 280 additions and 129 deletions

View File

@@ -32,9 +32,6 @@ export interface IQueryEditorService {
// Creates new edit data session
newEditDataEditor(schemaName: string, tableName: string, queryString: string): Promise<IConnectableInput>;
// Clears any QueryEditor data for the given URI held by this service
onQueryInputClosed(uri: string): void;
/**
* Handles updating of SQL files on a save as event. These need special consideration
* due to query results and other information being tied to the URI of the file

View File

@@ -116,11 +116,11 @@ export class QueryInput extends EditorInput implements IEncodingSupport, IConnec
}
if (this._configurationService) {
this._configurationService.onDidChangeConfiguration(e => {
this._toDispose.push(this._configurationService.onDidChangeConfiguration(e => {
if (e.affectedKeys.includes('sql.showConnectionInfoInTitle')) {
this._onDidChangeLabel.fire();
}
});
}));
}
this.onDisconnect();
@@ -196,17 +196,17 @@ export class QueryInput extends EditorInput implements IEncodingSupport, IConnec
// State update funtions
public runQuery(selection: ISelectionData, executePlanOptions?: ExecutionPlanOptions): void {
this._queryModelService.runQuery(this.uri, selection, this.uri, this, executePlanOptions);
this._queryModelService.runQuery(this.uri, selection, this, executePlanOptions);
this.showQueryResultsEditor();
}
public runQueryStatement(selection: ISelectionData): void {
this._queryModelService.runQueryStatement(this.uri, selection, this.uri, this);
this._queryModelService.runQueryStatement(this.uri, selection, this);
this.showQueryResultsEditor();
}
public runQueryString(text: string): void {
this._queryModelService.runQueryString(this.uri, text, this.uri, this);
this._queryModelService.runQueryString(this.uri, text, this);
this.showQueryResultsEditor();
}
@@ -276,7 +276,6 @@ export class QueryInput extends EditorInput implements IEncodingSupport, IConnec
// Clean up functions
public dispose(): void {
this._queryModelService.disposeQuery(this.uri);
this._sql.dispose();
this._results.dispose();
this._toDispose = dispose(this._toDispose);
@@ -285,7 +284,7 @@ export class QueryInput extends EditorInput implements IEncodingSupport, IConnec
}
public close(): void {
this._queryEditorService.onQueryInputClosed(this.uri);
this._queryModelService.disposeQuery(this.uri);
this._connectionManagementService.disconnectEditor(this, true);
this._sql.close();

View File

@@ -215,6 +215,7 @@ export class QueryManagementService implements IQueryManagementService {
});
}
public disposeQuery(ownerUri: string): Thenable<void> {
this._queryRunners.delete(ownerUri);
return this._runAction(ownerUri, (runner) => {
return runner.disposeQuery(ownerUri);
});

View File

@@ -29,6 +29,13 @@ export class ResultsViewState {
constructor(@IConfigurationService private configurationService: IConfigurationService) {
}
dispose() {
this.gridPanelState.dispose();
this.messagePanelState.dispose();
this.chartState.dispose();
this.queryPlanState.dispose();
}
}
/**
@@ -50,7 +57,11 @@ export class QueryResultsInput extends EditorInput {
public readonly onRestoreViewStateEmitter = new Emitter<void>();
public readonly onSaveViewStateEmitter = new Emitter<void>();
public readonly state = new ResultsViewState(this.configurationService);
private _state = new ResultsViewState(this.configurationService);
public get state(): ResultsViewState {
return this._state;
}
constructor(private _uri: string,
@IConfigurationService private configurationService: IConfigurationService
@@ -60,6 +71,12 @@ export class QueryResultsInput extends EditorInput {
this._hasBootstrapped = false;
}
close() {
this.state.dispose();
this._state = undefined;
super.close();
}
getTypeId(): string {
return QueryResultsInput.ID;
}

View File

@@ -33,4 +33,8 @@ export class ChartTab implements IPanelTab {
public dispose() {
this.view.dispose();
}
public clear() {
this.view.clear();
}
}

View File

@@ -35,6 +35,10 @@ export class ChartState {
options: IInsightOptions = {
type: ChartType.Bar
};
dispose() {
}
}
declare class Proxy {
@@ -134,6 +138,15 @@ export class ChartView extends Disposable implements IPanelView {
this.buildOptions();
}
public clear() {
}
public dispose() {
dispose(this.optionDisposables);
super.dispose();
}
render(container: HTMLElement): void {
if (!this.container) {
this.container = $('div.chart-parent-container');

View File

@@ -7,7 +7,7 @@
import { attachTableStyler } from 'sql/common/theme/styler';
import QueryRunner from 'sql/parts/query/execution/queryRunner';
import { VirtualizedCollection, AsyncDataProvider } from 'sql/base/browser/ui/table/asyncDataView';
import { Table, ITableStyles, ITableMouseEvent } from 'sql/base/browser/ui/table/table';
import { Table } from 'sql/base/browser/ui/table/table';
import { ScrollableSplitView } from 'sql/base/browser/ui/scrollableSplitview/scrollableSplitview';
import { MouseWheelSupport } from 'sql/base/browser/ui/table/plugins/mousewheelTableScroll.plugin';
import { AutoColumnSize } from 'sql/base/browser/ui/table/plugins/autoSizeColumns.plugin';
@@ -19,6 +19,7 @@ import { escape } from 'sql/base/common/strings';
import { hyperLinkFormatter, textFormatter } from 'sql/parts/grid/services/sharedServices';
import { CopyKeybind } from 'sql/base/browser/ui/table/plugins/copyKeybind.plugin';
import { AdditionalKeyBindings } from 'sql/base/browser/ui/table/plugins/additionalKeyBindings.plugin';
import { ITableStyles, ITableMouseEvent } from 'sql/base/browser/ui/table/interfaces';
import * as sqlops from 'sqlops';
import * as pretty from 'pretty-data';
@@ -61,6 +62,10 @@ export class GridPanelState {
public tableStates: GridTableState[] = [];
public scrollPosition: number;
public collapsed = false;
dispose() {
dispose(this.tableStates);
}
}
export interface IGridTableState {
@@ -68,14 +73,14 @@ export interface IGridTableState {
maximized: boolean;
}
export class GridTableState {
export class GridTableState extends Disposable {
private _maximized: boolean;
private _onMaximizedChange = new Emitter<boolean>();
private _onMaximizedChange = this._register(new Emitter<boolean>());
public onMaximizedChange: Event<boolean> = this._onMaximizedChange.event;
private _onCanBeMaximizedChange = new Emitter<boolean>();
private _onCanBeMaximizedChange = this._register(new Emitter<boolean>());
public onCanBeMaximizedChange: Event<boolean> = this._onCanBeMaximizedChange.event;
private _canBeMaximized: boolean;
@@ -86,6 +91,7 @@ export class GridTableState {
public activeCell: Slick.Cell;
constructor(public readonly resultId: number, public readonly batchId: number) {
super();
}
public get canBeMaximized(): boolean {
@@ -217,13 +223,13 @@ export class GridPanel extends ViewletPanel {
}
let table = this.instantiationService.createInstance(GridTable, this.runner, set);
table.state = tableState;
tableState.onMaximizedChange(e => {
this.tableDisposable.push(tableState.onMaximizedChange(e => {
if (e) {
this.maximizeTable(table.id);
} else {
this.minimizeTables();
}
});
}));
this.tableDisposable.push(attachTableStyler(table, this.themeService));
tables.push(table);
@@ -238,11 +244,17 @@ export class GridPanel extends ViewletPanel {
this.tables = this.tables.concat(tables);
}
public clear() {
this.reset();
}
private reset() {
for (let i = this.splitView.length - 1; i >= 0; i--) {
this.splitView.removeView(i);
}
dispose(this.tables);
dispose(this.tableDisposable);
this.tableDisposable = [];
this.tables = [];
this.maximizedGrid = undefined;
@@ -293,6 +305,15 @@ export class GridPanel extends ViewletPanel {
public get state(): GridPanelState {
return this._state;
}
public dispose() {
dispose(this.queryRunnerDisposables);
dispose(this.tableDisposable);
dispose(this.tables);
this.tableDisposable = undefined;
this.tables = undefined;
super.dispose();
}
}
class GridTable<T> extends Disposable implements IView {
@@ -444,9 +465,9 @@ class GridTable<T> extends Disposable implements IView {
private setupState() {
// change actionbar on maximize change
this.state.onMaximizedChange(this.rebuildActionBar, this);
this._register(this.state.onMaximizedChange(this.rebuildActionBar, this));
this.state.onCanBeMaximizedChange(this.rebuildActionBar, this);
this._register(this.state.onCanBeMaximizedChange(this.rebuildActionBar, this));
if (this.state.scrollPosition) {
// most of the time this won't do anything
@@ -656,6 +677,8 @@ class GridTable<T> extends Disposable implements IView {
public dispose() {
$(this.container).destroy();
this.table.dispose();
this.actionBar.dispose();
super.dispose();
}
}

View File

@@ -7,6 +7,7 @@
import 'vs/css!./media/messagePanel';
import { IMessagesActionContext, SelectAllMessagesAction, CopyMessagesAction } from './actions';
import QueryRunner from 'sql/parts/query/execution/queryRunner';
import { QueryInput } from 'sql/parts/query/common/queryInput';
import { IResultMessage, ISelectionData } from 'sqlops';
@@ -28,8 +29,6 @@ import { $ } from 'vs/base/browser/builder';
import { isArray, isUndefinedOrNull } from 'vs/base/common/types';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IEditor } from 'vs/editor/common/editorCommon';
import { QueryInput } from 'sql/parts/query/common/queryInput';
import { ScrollbarVisibility } from 'vs/base/common/scrollable';
export interface IResultMessageIntern extends IResultMessage {
@@ -71,6 +70,10 @@ export class MessagePanelState {
this.collapsed = !messagesOpenedSettings;
}
}
dispose() {
}
}
export class MessagePanel extends ViewletPanel {
@@ -102,6 +105,7 @@ export class MessagePanel extends ViewletPanel {
renderer: this.renderer,
controller: this.controller
}, { keyboardSupport: false, horizontalScrollMode: ScrollbarVisibility.Auto });
this.disposables.push(this.tree);
this.tree.onDidScroll(e => {
if (this.state) {
this.state.scrollPosition = this.tree.getScrollPosition();
@@ -117,7 +121,7 @@ export class MessagePanel extends ViewletPanel {
protected renderBody(container: HTMLElement): void {
this.container.style.width = '100%';
this.container.style.height = '100%';
attachListStyler(this.tree, this.themeService);
this.disposables.push(attachListStyler(this.tree, this.themeService));
container.appendChild(this.container);
this.tree.setInput(this.model);
}
@@ -193,9 +197,19 @@ export class MessagePanel extends ViewletPanel {
}
this.setExpanded(!this.state.collapsed);
}
public get state(): MessagePanelState {
return this._state;
}
public clear() {
this.reset();
}
public dispose() {
dispose(this.queryRunnerDisposables);
super.dispose();
}
}
class MessageDataSource implements IDataSource {

View File

@@ -478,11 +478,11 @@ export class QueryEditor extends BaseEditor {
this.setTaskbarContent();
this._configurationService.onDidChangeConfiguration(e => {
this._toDispose.push(this._configurationService.onDidChangeConfiguration(e => {
if (e.affectedKeys.includes('workbench.enablePreviewFeatures')) {
this.setTaskbarContent();
}
});
}));
}
private setTaskbarContent(): void {

View File

@@ -90,7 +90,6 @@ export class QueryResultsEditor extends BaseEditor {
public static ID: string = 'workbench.editor.queryResultsEditor';
public static AngularSelectorString: string = 'slickgrid-container.slickgridContainer';
protected _rawOptions: BareResultsGridInfo;
protected _input: QueryResultsInput;
private resultsView: QueryResultsView;
private styleSheet = DOM.createStyleSheet();
@@ -104,17 +103,17 @@ export class QueryResultsEditor extends BaseEditor {
) {
super(QueryResultsEditor.ID, telemetryService, themeService);
this._rawOptions = BareResultsGridInfo.createFromRawSettings(this._configurationService.getValue('resultsGrid'), getZoomLevel());
this._configurationService.onDidChangeConfiguration(e => {
this._register(this._configurationService.onDidChangeConfiguration(e => {
if (e.affectsConfiguration('resultsGrid')) {
this._rawOptions = BareResultsGridInfo.createFromRawSettings(this._configurationService.getValue('resultsGrid'), getZoomLevel());
this.applySettings();
}
});
}));
this.applySettings();
}
public get input(): QueryResultsInput {
return this._input;
return this._input as QueryResultsInput;
}
private applySettings() {
@@ -133,10 +132,16 @@ export class QueryResultsEditor extends BaseEditor {
this.styleSheet.remove();
parent.appendChild(this.styleSheet);
if (!this.resultsView) {
this.resultsView = new QueryResultsView(parent, this._instantiationService, this._queryModelService);
this.resultsView = this._register(new QueryResultsView(parent, this._instantiationService, this._queryModelService));
}
}
dispose() {
this.styleSheet.remove();
this.styleSheet = undefined;
super.dispose();
}
layout(dimension: DOM.Dimension): void {
this.resultsView.layout(dimension);
}
@@ -147,6 +152,11 @@ export class QueryResultsEditor extends BaseEditor {
return TPromise.wrap<void>(null);
}
clearInput() {
this.resultsView.clearInput();
super.clearInput();
}
public chart(dataId: { batchId: number, resultId: number }) {
this.resultsView.chartData(dataId);
}
@@ -154,11 +164,4 @@ export class QueryResultsEditor extends BaseEditor {
public showQueryPlan(xml: string) {
this.resultsView.showPlan(xml);
}
public dispose(): void {
super.dispose();
if (this.resultsView) {
this.resultsView.dispose();
}
}
}

View File

@@ -111,6 +111,15 @@ class ResultsView extends Disposable implements IPanelView {
}
}
dispose() {
super.dispose();
}
public clear() {
this.gridPanel.clear();
this.messagePanel.clear();
}
remove(): void {
this.container.remove();
}
@@ -151,6 +160,10 @@ class ResultsTab implements IPanelTab {
public dispose() {
dispose(this.view);
}
public clear() {
this.view.clear();
}
}
export class QueryResultsView extends Disposable {
@@ -221,8 +234,11 @@ export class QueryResultsView extends Disposable {
}
}
public dispose() {
this._panelView.dispose();
clearInput() {
this._input = undefined;
this.resultsTab.clear();
this.qpTab.clear();
this.chartTab.clear();
}
public get input(): QueryResultsInput {
@@ -264,4 +280,8 @@ export class QueryResultsView extends Disposable {
this._panelView.removeTab(this.qpTab.identifier);
}
}
public dispose() {
super.dispose();
}
}

View File

@@ -35,9 +35,9 @@ export interface IQueryModelService {
getConfig(): Promise<{ [key: string]: any }>;
getShortcuts(): Promise<any>;
getQueryRows(uri: string, rowStart: number, numberOfRows: number, batchId: number, resultId: number): Thenable<ResultSetSubset>;
runQuery(uri: string, selection: ISelectionData, title: string, queryInput: QueryInput, runOptions?: ExecutionPlanOptions): void;
runQueryStatement(uri: string, selection: ISelectionData, title: string, queryInput: QueryInput): void;
runQueryString(uri: string, selection: string, title: string, queryInput: QueryInput);
runQuery(uri: string, selection: ISelectionData, queryInput: QueryInput, runOptions?: ExecutionPlanOptions): void;
runQueryStatement(uri: string, selection: ISelectionData, queryInput: QueryInput): void;
runQueryString(uri: string, selection: string, queryInput: QueryInput);
cancelQuery(input: QueryRunner | string): void;
disposeQuery(uri: string): void;
isRunningQuery(uri: string): boolean;

View File

@@ -209,32 +209,28 @@ export class QueryModelService implements IQueryModelService {
/**
* Run a query for the given URI with the given text selection
*/
public runQuery(uri: string, selection: sqlops.ISelectionData,
title: string, queryInput: QueryInput, runOptions?: sqlops.ExecutionPlanOptions): void {
this.doRunQuery(uri, selection, title, queryInput, false, runOptions);
public runQuery(uri: string, selection: sqlops.ISelectionData, queryInput: QueryInput, runOptions?: sqlops.ExecutionPlanOptions): void {
this.doRunQuery(uri, selection, queryInput, false, runOptions);
}
/**
* Run the current SQL statement for the given URI
*/
public runQueryStatement(uri: string, selection: sqlops.ISelectionData,
title: string, queryInput: QueryInput): void {
this.doRunQuery(uri, selection, title, queryInput, true);
public runQueryStatement(uri: string, selection: sqlops.ISelectionData, queryInput: QueryInput): void {
this.doRunQuery(uri, selection, queryInput, true);
}
/**
* Run the current SQL statement for the given URI
*/
public runQueryString(uri: string, selection: string,
title: string, queryInput: QueryInput): void {
this.doRunQuery(uri, selection, title, queryInput, true);
public runQueryString(uri: string, selection: string, queryInput: QueryInput): void {
this.doRunQuery(uri, selection, queryInput, true);
}
/**
* Run Query implementation
*/
private doRunQuery(uri: string, selection: sqlops.ISelectionData | string,
title: string, queryInput: QueryInput,
private doRunQuery(uri: string, selection: sqlops.ISelectionData | string, queryInput: QueryInput,
runCurrentStatement: boolean, runOptions?: sqlops.ExecutionPlanOptions): void {
// Reuse existing query runner if it exists
let queryRunner: QueryRunner;
@@ -256,7 +252,7 @@ export class QueryModelService implements IQueryModelService {
} else {
// We do not have a query runner for this editor, so create a new one
// and map it to the results uri
info = this.initQueryRunner(uri, title);
info = this.initQueryRunner(uri);
queryRunner = info.queryRunner;
}
@@ -277,8 +273,8 @@ export class QueryModelService implements IQueryModelService {
}
}
private initQueryRunner(uri: string, title: string): QueryInfo {
let queryRunner = this._instantiationService.createInstance(QueryRunner, uri, title);
private initQueryRunner(uri: string): QueryInfo {
let queryRunner = this._instantiationService.createInstance(QueryRunner, uri);
let info = new QueryInfo();
queryRunner.addListener(QREvents.RESULT_SET, e => {
this._fireQueryEvent(uri, 'resultSet', e);
@@ -363,6 +359,10 @@ export class QueryModelService implements IQueryModelService {
if (queryRunner) {
queryRunner.disposeQuery();
}
// remove our info map
if (this._queryInfoMap.has(ownerUri)) {
this._queryInfoMap.delete(ownerUri);
}
}
// EDIT DATA METHODS /////////////////////////////////////////////////////
@@ -386,7 +386,7 @@ export class QueryModelService implements IQueryModelService {
// We do not have a query runner for this editor, so create a new one
// and map it to the results uri
queryRunner = this._instantiationService.createInstance(QueryRunner, ownerUri, ownerUri);
queryRunner = this._instantiationService.createInstance(QueryRunner, ownerUri);
queryRunner.addListener(QREvents.RESULT_SET, resultSet => {
this._fireQueryEvent(ownerUri, 'resultSet', resultSet);
});

View File

@@ -20,7 +20,7 @@ import * as nls from 'vs/nls';
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
import * as types from 'vs/base/common/types';
import { EventEmitter } from 'sql/base/common/eventEmitter';
import { IDisposable } from 'vs/base/common/lifecycle';
import { IDisposable, Disposable } from 'vs/base/common/lifecycle';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { Emitter, Event } from 'vs/base/common/event';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
@@ -62,7 +62,7 @@ export interface IGridMessage extends sqlops.IResultMessage {
* Query Runner class which handles running a query, reports the results to the content manager,
* and handles getting more rows from the service layer and disposing when the content is closed.
*/
export default class QueryRunner {
export default class QueryRunner extends Disposable {
// MEMBER VARIABLES ////////////////////////////////////////////////////
private _resultLineOffset: number;
private _totalElapsedMilliseconds: number = 0;
@@ -76,7 +76,7 @@ export default class QueryRunner {
private _planXml = new Deferred<string>();
public get planXml(): Thenable<string> { return this._planXml.promise; }
private _onMessage = new Emitter<sqlops.IResultMessage>();
private _onMessage = this._register(new Emitter<sqlops.IResultMessage>());
private _debouncedMessage = debounceEvent<sqlops.IResultMessage, sqlops.IResultMessage[]>(this._onMessage.event, (l, e) => {
// on first run
if (types.isUndefinedOrNull(l)) {
@@ -88,7 +88,7 @@ export default class QueryRunner {
private _echoedMessages = echo(this._debouncedMessage.event);
public readonly onMessage = this._echoedMessages.event;
private _onResultSet = new Emitter<sqlops.ResultSetSummary>();
private _onResultSet = this._register(new Emitter<sqlops.ResultSetSummary>());
private _debouncedResultSet = debounceEvent<sqlops.ResultSetSummary, sqlops.ResultSetSummary[]>(this._onResultSet.event, (l, e) => {
// on first run
if (types.isUndefinedOrNull(l)) {
@@ -100,16 +100,16 @@ export default class QueryRunner {
private _echoedResultSet = echo(this._debouncedResultSet.event);
public readonly onResultSet = this._echoedResultSet.event;
private _onQueryStart = new Emitter<void>();
private _onQueryStart = this._register(new Emitter<void>());
public readonly onQueryStart: Event<void> = this._onQueryStart.event;
private _onQueryEnd = new Emitter<string>();
private _onQueryEnd = this._register(new Emitter<string>());
public readonly onQueryEnd: Event<string> = this._onQueryEnd.event;
private _onBatchStart = new Emitter<sqlops.BatchSummary>();
private _onBatchStart = this._register(new Emitter<sqlops.BatchSummary>());
public readonly onBatchStart: Event<sqlops.BatchSummary> = this._onBatchStart.event;
private _onBatchEnd = new Emitter<sqlops.BatchSummary>();
private _onBatchEnd = this._register(new Emitter<sqlops.BatchSummary>());
public readonly onBatchEnd: Event<sqlops.BatchSummary> = this._onBatchEnd.event;
private _queryStartTime: Date;
@@ -124,13 +124,14 @@ export default class QueryRunner {
// CONSTRUCTOR /////////////////////////////////////////////////////////
constructor(
public uri: string,
public title: string,
@IQueryManagementService private _queryManagementService: IQueryManagementService,
@INotificationService private _notificationService: INotificationService,
@IWorkspaceConfigurationService private _workspaceConfigurationService: IWorkspaceConfigurationService,
@IClipboardService private _clipboardService: IClipboardService,
@IInstantiationService private instantiationService: IInstantiationService
) { }
) {
super();
}
get isExecuting(): boolean {
return this._isExecuting;
@@ -504,10 +505,16 @@ export default class QueryRunner {
/**
* Disposes the Query from the service client
* @returns A promise that will be rejected if a problem occured
*/
public disposeQuery(): void {
this._queryManagementService.disposeQuery(this.uri);
this._queryManagementService.disposeQuery(this.uri).then(() => {
this.dispose();
});
}
public dispose() {
this._batchSets = undefined;
super.dispose();
}
get totalElapsedMilliseconds(): number {

View File

@@ -152,12 +152,6 @@ export class QueryEditorService implements IQueryEditorService {
});
}
/**
* Clears any QueryEditor data for the given URI held by this service
*/
public onQueryInputClosed(uri: string): void {
}
onSaveAsCompleted(oldResource: URI, newResource: URI): void {
let oldResourceString: string = oldResource.toString();