Regularly scrub query history view
This commit is contained in:
committed by
Edoardo Pirovano
parent
bbf4a03b03
commit
bd2dd04ac6
@@ -3,6 +3,7 @@ import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
import { Disposable, ExtensionContext } from 'vscode';
|
||||
import { logger } from './logging';
|
||||
import { QueryHistoryManager } from './query-history';
|
||||
|
||||
const LAST_SCRUB_TIME_KEY = 'lastScrubTime';
|
||||
|
||||
@@ -30,12 +31,13 @@ export function registerQueryHistoryScubber(
|
||||
throttleTime: number,
|
||||
maxQueryTime: number,
|
||||
queryDirectory: string,
|
||||
qhm: QueryHistoryManager,
|
||||
ctx: ExtensionContext,
|
||||
|
||||
// optional counter to keep track of how many times the scrubber has run
|
||||
counter?: Counter
|
||||
): Disposable {
|
||||
const deregister = setInterval(scrubQueries, wakeInterval, throttleTime, maxQueryTime, queryDirectory, ctx, counter);
|
||||
const deregister = setInterval(scrubQueries, wakeInterval, throttleTime, maxQueryTime, queryDirectory, qhm, ctx, counter);
|
||||
|
||||
return {
|
||||
dispose: () => {
|
||||
@@ -48,6 +50,7 @@ async function scrubQueries(
|
||||
throttleTime: number,
|
||||
maxQueryTime: number,
|
||||
queryDirectory: string,
|
||||
qhm: QueryHistoryManager,
|
||||
ctx: ExtensionContext,
|
||||
counter?: Counter
|
||||
) {
|
||||
@@ -89,6 +92,7 @@ async function scrubQueries(
|
||||
} finally {
|
||||
void logger.log(`Scrubbed ${scrubCount} old queries.`);
|
||||
}
|
||||
await qhm.removeDeletedQueries();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -505,7 +505,7 @@ export class QueryHistoryManager extends DisposableObject {
|
||||
this.push(
|
||||
queryHistoryConfigListener.onDidChangeConfiguration(() => {
|
||||
this.treeDataProvider.refresh();
|
||||
this.registerQueryHistoryScrubber(queryHistoryConfigListener, ctx);
|
||||
this.registerQueryHistoryScrubber(queryHistoryConfigListener, this, ctx);
|
||||
})
|
||||
);
|
||||
|
||||
@@ -524,7 +524,7 @@ export class QueryHistoryManager extends DisposableObject {
|
||||
},
|
||||
}));
|
||||
|
||||
this.registerQueryHistoryScrubber(queryHistoryConfigListener, ctx);
|
||||
this.registerQueryHistoryScrubber(queryHistoryConfigListener, this, ctx);
|
||||
this.registerToRemoteQueriesEvents();
|
||||
}
|
||||
|
||||
@@ -535,7 +535,7 @@ export class QueryHistoryManager extends DisposableObject {
|
||||
/**
|
||||
* Register and create the history scrubber.
|
||||
*/
|
||||
private registerQueryHistoryScrubber(queryHistoryConfigListener: QueryHistoryConfig, ctx: ExtensionContext) {
|
||||
private registerQueryHistoryScrubber(queryHistoryConfigListener: QueryHistoryConfig, qhm: QueryHistoryManager, ctx: ExtensionContext) {
|
||||
this.queryHistoryScrubber?.dispose();
|
||||
// Every hour check if we need to re-run the query history scrubber.
|
||||
this.queryHistoryScrubber = this.push(
|
||||
@@ -544,6 +544,7 @@ export class QueryHistoryManager extends DisposableObject {
|
||||
TWO_HOURS_IN_MS,
|
||||
queryHistoryConfigListener.ttlInMillis,
|
||||
this.queryStorageDir,
|
||||
qhm,
|
||||
ctx
|
||||
)
|
||||
);
|
||||
@@ -639,6 +640,15 @@ export class QueryHistoryManager extends DisposableObject {
|
||||
return this.treeDataProvider.getCurrent();
|
||||
}
|
||||
|
||||
async removeDeletedQueries() {
|
||||
await Promise.all(this.treeDataProvider.allHistory.map(async (item) => {
|
||||
if (item.t == 'local' && item.completedQuery && !(await fs.pathExists(item.completedQuery?.query.querySaveDir))) {
|
||||
this.treeDataProvider.remove(item);
|
||||
item.completedQuery?.dispose();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
async handleRemoveHistoryItem(
|
||||
singleItem: QueryHistoryInfo,
|
||||
multiSelect: QueryHistoryInfo[] = []
|
||||
|
||||
@@ -762,6 +762,9 @@ describe('query-history', () => {
|
||||
TWO_HOURS_IN_MS,
|
||||
LESS_THAN_ONE_DAY,
|
||||
dir,
|
||||
{
|
||||
removeDeletedQueries: () => { return Promise.resolve(); }
|
||||
} as QueryHistoryManager,
|
||||
mockCtx,
|
||||
{
|
||||
increment: () => runCount++
|
||||
|
||||
Reference in New Issue
Block a user