mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-13 17:22:15 -05:00
Add max entries to query history (#20715)
This commit is contained in:
@@ -55,6 +55,12 @@
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
"description": "%queryHistory.persistHistory%"
|
||||
},
|
||||
"queryHistory.maxEntries": {
|
||||
"type": "integer",
|
||||
"default": 100,
|
||||
"minimum": 0,
|
||||
"description": "%queryHistory.maxEntries%"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,5 +12,6 @@
|
||||
"queryHistory.clear": "Clear All History",
|
||||
"queryHistory.disableCapture": "Pause Query History Capture",
|
||||
"queryHistory.enableCapture": "Start Query History Capture",
|
||||
"queryHistory.noEntries": "No queries to display"
|
||||
"queryHistory.noEntries": "No queries to display",
|
||||
"queryHistory.maxEntries": "Maximum number of entries to store. 0 means unlimited entries are stored. Increasing this limit may impact performance, especially if persistence is enabled."
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ export const QUERY_HISTORY_CONFIG_SECTION = 'queryHistory';
|
||||
export const CAPTURE_ENABLED_CONFIG_SECTION = 'captureEnabled';
|
||||
export const DOUBLE_CLICK_ACTION_CONFIG_SECTION = 'doubleClickAction';
|
||||
export const PERSIST_HISTORY_CONFIG_SECTION = 'persistHistory';
|
||||
export const MAX_ENTRIES_CONFIG_SECTION = 'maxEntries';
|
||||
|
||||
export const ITEM_SELECTED_COMMAND_ID = 'queryHistory.itemSelected';
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import * as vscode from 'vscode';
|
||||
import * as azdata from 'azdata';
|
||||
import { QueryHistoryItem } from './queryHistoryItem';
|
||||
import { debounce, removeNewLines } from './utils';
|
||||
import { CAPTURE_ENABLED_CONFIG_SECTION, ITEM_SELECTED_COMMAND_ID, PERSIST_HISTORY_CONFIG_SECTION, QUERY_HISTORY_CONFIG_SECTION } from './constants';
|
||||
import { CAPTURE_ENABLED_CONFIG_SECTION, ITEM_SELECTED_COMMAND_ID, MAX_ENTRIES_CONFIG_SECTION, PERSIST_HISTORY_CONFIG_SECTION, QUERY_HISTORY_CONFIG_SECTION } from './constants';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as crypto from 'crypto';
|
||||
@@ -20,6 +20,7 @@ const STORAGE_ENCRYPTION_ALGORITHM = 'aes-256-ctr';
|
||||
const HISTORY_DEBOUNCE_MS = 10000;
|
||||
const DEFAULT_CAPTURE_ENABLED = true;
|
||||
const DEFAULT_PERSIST_HISTORY = true;
|
||||
const DEFAULT_MAX_ENTRIES = 100;
|
||||
const successIcon = new vscode.ThemeIcon('check', new vscode.ThemeColor('testing.iconPassed'));
|
||||
const failedIcon = new vscode.ThemeIcon('error', new vscode.ThemeColor('testing.iconFailed'));
|
||||
|
||||
@@ -31,7 +32,7 @@ export class QueryHistoryProvider implements vscode.TreeDataProvider<QueryHistor
|
||||
private _queryHistoryItems: QueryHistoryItem[] = [];
|
||||
private _captureEnabled: boolean = DEFAULT_CAPTURE_ENABLED;
|
||||
private _persistHistory: boolean = DEFAULT_PERSIST_HISTORY;
|
||||
|
||||
private _maxEntries: number = DEFAULT_MAX_ENTRIES;
|
||||
private _historyStorageFile: string;
|
||||
|
||||
private _disposables: vscode.Disposable[] = [];
|
||||
@@ -49,7 +50,7 @@ export class QueryHistoryProvider implements vscode.TreeDataProvider<QueryHistor
|
||||
// Kick off initialization but then continue on since that may take a while and we don't want to block extension activation
|
||||
void this.initialize();
|
||||
this._disposables.push(vscode.workspace.onDidChangeConfiguration(async e => {
|
||||
if (e.affectsConfiguration(QUERY_HISTORY_CONFIG_SECTION)) {
|
||||
if (e.affectsConfiguration(QUERY_HISTORY_CONFIG_SECTION) || e.affectsConfiguration(MAX_ENTRIES_CONFIG_SECTION)) {
|
||||
await this.updateConfigurationValues();
|
||||
}
|
||||
}));
|
||||
@@ -67,6 +68,7 @@ export class QueryHistoryProvider implements vscode.TreeDataProvider<QueryHistor
|
||||
}
|
||||
this.queryTextMappings.delete(document.uri);
|
||||
this._queryHistoryItems.unshift({ queryText, connectionProfile, timestamp: new Date().toLocaleString(), isSuccess });
|
||||
this.trimExtraEntries();
|
||||
this._onDidChangeTreeData.fire(undefined);
|
||||
this.writeHistoryFile();
|
||||
} else if (type === 'queryStart') {
|
||||
@@ -222,6 +224,8 @@ export class QueryHistoryProvider implements vscode.TreeDataProvider<QueryHistor
|
||||
const configSection = vscode.workspace.getConfiguration(QUERY_HISTORY_CONFIG_SECTION);
|
||||
this._captureEnabled = configSection.get(CAPTURE_ENABLED_CONFIG_SECTION, DEFAULT_CAPTURE_ENABLED);
|
||||
this._persistHistory = configSection.get(PERSIST_HISTORY_CONFIG_SECTION, DEFAULT_PERSIST_HISTORY);
|
||||
this._maxEntries = configSection.get(MAX_ENTRIES_CONFIG_SECTION, DEFAULT_MAX_ENTRIES);
|
||||
this.trimExtraEntries();
|
||||
if (!this._persistHistory) {
|
||||
// If we're no longer persisting the history then clean up our storage file
|
||||
try {
|
||||
@@ -238,6 +242,16 @@ export class QueryHistoryProvider implements vscode.TreeDataProvider<QueryHistor
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the oldest entries from the items list if there are more than maxEntries
|
||||
* currently being tracked.
|
||||
*/
|
||||
private trimExtraEntries(): void {
|
||||
if (this._queryHistoryItems.length > this._maxEntries) {
|
||||
this._queryHistoryItems.length = this._maxEntries;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether query history capture is currently enabled
|
||||
* @param enabled Whether capture is currently enabled
|
||||
|
||||
Reference in New Issue
Block a user