Skip to content

Commit 66e9272

Browse files
committed
feat: Remove side log location when query removed
When removing query history item from view, also remove the side log. Log files can be large, so ensure they don't stick around. Last piece of #236 and #234.
1 parent 6793f8e commit 66e9272

File tree

4 files changed

+22
-12
lines changed

4 files changed

+22
-12
lines changed

extensions/ql-vscode/src/logging.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export interface Logger {
2525
* Remove the log at the specified location
2626
* @param location log to remove
2727
*/
28-
removeAdditionalLogLocation(location: string): void;
28+
removeAdditionalLogLocation(location: string | undefined): void;
2929

3030
/**
3131
* The base location location where all side log files are stored.
@@ -93,9 +93,11 @@ export class OutputChannelLogger extends DisposableObject implements Logger {
9393
this.outputChannel.show(preserveFocus);
9494
}
9595

96-
removeAdditionalLogLocation(location: string): void {
97-
if (this.additionalLogLocationPath) {
98-
const logPath = path.join(this.additionalLogLocationPath, location);
96+
removeAdditionalLogLocation(location: string | undefined): void {
97+
if (this.additionalLogLocationPath && location) {
98+
const logPath = location.startsWith(this.additionalLogLocationPath)
99+
? location
100+
: path.join(this.additionalLogLocationPath, location);
99101
const additional = this.additionalLocations.get(logPath);
100102
if (additional) {
101103
this.disposeAndStopTracking(additional);

extensions/ql-vscode/src/query-history.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ export class QueryHistoryManager {
145145

146146
async handleRemoveHistoryItem(queryHistoryItem: CompletedQuery) {
147147
this.treeDataProvider.remove(queryHistoryItem);
148+
queryHistoryItem.dispose();
148149
const current = this.treeDataProvider.getCurrent();
149150
if (current !== undefined) {
150151
this.treeView.reveal(current);

extensions/ql-vscode/src/query-results.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export class CompletedQuery implements QueryWithResults {
1616
readonly database: DatabaseInfo;
1717
readonly logFileLocation?: string
1818
options: QueryHistoryItemOptions;
19+
dispose: () => void;
1920

2021
/**
2122
* Map from result set name to SortedResultSetInfo.
@@ -32,16 +33,18 @@ export class CompletedQuery implements QueryWithResults {
3233
interpretedResultsSortState: InterpretedResultsSortState | undefined;
3334

3435
constructor(
35-
evalaution: QueryWithResults,
36+
evaluation: QueryWithResults,
3637
public config: QueryHistoryConfig,
3738
) {
38-
this.query = evalaution.query;
39-
this.result = evalaution.result;
40-
this.database = evalaution.database;
41-
this.logFileLocation = evalaution.logFileLocation;
39+
this.query = evaluation.query;
40+
this.result = evaluation.result;
41+
this.database = evaluation.database;
42+
this.logFileLocation = evaluation.logFileLocation;
43+
this.options = evaluation.options;
44+
this.dispose = evaluation.dispose;
45+
4246
this.time = new Date().toLocaleString();
4347
this.sortedResultsInfo = new Map();
44-
this.options = evalaution.options;
4548
}
4649

4750
get databaseName(): string {

extensions/ql-vscode/src/run-queries.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ export class QueryInfo {
143143
}
144144
};
145145

146-
147146
compiled = await helpers.withProgress({
148147
location: vscode.ProgressLocation.Notification,
149148
title: "Compiling Query",
@@ -175,6 +174,7 @@ export interface QueryWithResults {
175174
readonly database: DatabaseInfo;
176175
readonly options: QueryHistoryItemOptions;
177176
readonly logFileLocation?: string;
177+
readonly dispose: () => void;
178178
}
179179

180180
export async function clearCacheInDatabase(
@@ -464,7 +464,10 @@ export async function compileAndRunQueryAgainstDatabase(
464464
databaseUri: db.databaseUri.toString(true)
465465
},
466466
options: historyItemOptions,
467-
logFileLocation: result.logFileLocation
467+
logFileLocation: result.logFileLocation,
468+
dispose: () => {
469+
qs.logger.removeAdditionalLogLocation(result.logFileLocation);
470+
}
468471
};
469472
} else {
470473
// Error dialogs are limited in size and scrollability,
@@ -516,5 +519,6 @@ function createSyntheticResult(
516519
databaseUri: db.databaseUri.toString(true)
517520
},
518521
options: historyItemOptions,
522+
dispose: () => { /**/ },
519523
};
520524
}

0 commit comments

Comments
 (0)