Skip to content

Commit d610c96

Browse files
Regularly scrub query history view
1 parent bbf4a03 commit d610c96

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as os from 'os';
33
import * as path from 'path';
44
import { Disposable, ExtensionContext } from 'vscode';
55
import { logger } from './logging';
6+
import { QueryHistoryManager } from './query-history';
67

78
const LAST_SCRUB_TIME_KEY = 'lastScrubTime';
89

@@ -30,12 +31,13 @@ export function registerQueryHistoryScubber(
3031
throttleTime: number,
3132
maxQueryTime: number,
3233
queryDirectory: string,
34+
qhm: QueryHistoryManager,
3335
ctx: ExtensionContext,
3436

3537
// optional counter to keep track of how many times the scrubber has run
3638
counter?: Counter
3739
): Disposable {
38-
const deregister = setInterval(scrubQueries, wakeInterval, throttleTime, maxQueryTime, queryDirectory, ctx, counter);
40+
const deregister = setInterval(scrubQueries, wakeInterval, throttleTime, maxQueryTime, queryDirectory, qhm, ctx, counter);
3941

4042
return {
4143
dispose: () => {
@@ -48,6 +50,7 @@ async function scrubQueries(
4850
throttleTime: number,
4951
maxQueryTime: number,
5052
queryDirectory: string,
53+
qhm: QueryHistoryManager,
5154
ctx: ExtensionContext,
5255
counter?: Counter
5356
) {
@@ -89,6 +92,7 @@ async function scrubQueries(
8992
} finally {
9093
void logger.log(`Scrubbed ${scrubCount} old queries.`);
9194
}
95+
await qhm.removeDeletedQueries();
9296
}
9397
}
9498

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ export class QueryHistoryManager extends DisposableObject {
505505
this.push(
506506
queryHistoryConfigListener.onDidChangeConfiguration(() => {
507507
this.treeDataProvider.refresh();
508-
this.registerQueryHistoryScrubber(queryHistoryConfigListener, ctx);
508+
this.registerQueryHistoryScrubber(queryHistoryConfigListener, this, ctx);
509509
})
510510
);
511511

@@ -524,7 +524,7 @@ export class QueryHistoryManager extends DisposableObject {
524524
},
525525
}));
526526

527-
this.registerQueryHistoryScrubber(queryHistoryConfigListener, ctx);
527+
this.registerQueryHistoryScrubber(queryHistoryConfigListener, this, ctx);
528528
this.registerToRemoteQueriesEvents();
529529
}
530530

@@ -535,7 +535,7 @@ export class QueryHistoryManager extends DisposableObject {
535535
/**
536536
* Register and create the history scrubber.
537537
*/
538-
private registerQueryHistoryScrubber(queryHistoryConfigListener: QueryHistoryConfig, ctx: ExtensionContext) {
538+
private registerQueryHistoryScrubber(queryHistoryConfigListener: QueryHistoryConfig, qhm: QueryHistoryManager, ctx: ExtensionContext) {
539539
this.queryHistoryScrubber?.dispose();
540540
// Every hour check if we need to re-run the query history scrubber.
541541
this.queryHistoryScrubber = this.push(
@@ -544,6 +544,7 @@ export class QueryHistoryManager extends DisposableObject {
544544
TWO_HOURS_IN_MS,
545545
queryHistoryConfigListener.ttlInMillis,
546546
this.queryStorageDir,
547+
qhm,
547548
ctx
548549
)
549550
);
@@ -639,6 +640,15 @@ export class QueryHistoryManager extends DisposableObject {
639640
return this.treeDataProvider.getCurrent();
640641
}
641642

643+
async removeDeletedQueries() {
644+
await Promise.all(this.treeDataProvider.allHistory.map(async (item) => {
645+
if (item.t == 'local' && item.completedQuery && !(await fs.pathExists(item.completedQuery?.query.querySaveDir))) {
646+
this.treeDataProvider.remove(item);
647+
item.completedQuery?.dispose();
648+
}
649+
}));
650+
}
651+
642652
async handleRemoveHistoryItem(
643653
singleItem: QueryHistoryInfo,
644654
multiSelect: QueryHistoryInfo[] = []

extensions/ql-vscode/src/vscode-tests/no-workspace/query-history.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,9 @@ describe('query-history', () => {
762762
TWO_HOURS_IN_MS,
763763
LESS_THAN_ONE_DAY,
764764
dir,
765+
{
766+
removeDeletedQueries: () => { return Promise.resolve(); }
767+
} as QueryHistoryManager,
765768
mockCtx,
766769
{
767770
increment: () => runCount++

0 commit comments

Comments
 (0)