Pass both local queries and variant analyses dirs in query history scrubber
This commit is contained in:
@@ -131,6 +131,7 @@ import { ExtensionApp } from "./common/vscode/vscode-app";
|
|||||||
import { RepositoriesFilterSortStateWithIds } from "./pure/variant-analysis-filter-sort";
|
import { RepositoriesFilterSortStateWithIds } from "./pure/variant-analysis-filter-sort";
|
||||||
import { DbModule } from "./databases/db-module";
|
import { DbModule } from "./databases/db-module";
|
||||||
import { redactableError } from "./pure/errors";
|
import { redactableError } from "./pure/errors";
|
||||||
|
import { QueryHistoryDirs } from "./query-history/query-history-dirs";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* extension.ts
|
* extension.ts
|
||||||
@@ -649,13 +650,18 @@ async function activateWithInstalledDistribution(
|
|||||||
);
|
);
|
||||||
|
|
||||||
void extLogger.log("Initializing query history.");
|
void extLogger.log("Initializing query history.");
|
||||||
|
const queryHistoryDirs: QueryHistoryDirs = {
|
||||||
|
localQueriesDirPath: queryStorageDir,
|
||||||
|
variantAnalysesDirPath: variantAnalysisStorageDir,
|
||||||
|
};
|
||||||
|
|
||||||
const qhm = new QueryHistoryManager(
|
const qhm = new QueryHistoryManager(
|
||||||
qs,
|
qs,
|
||||||
dbm,
|
dbm,
|
||||||
localQueryResultsView,
|
localQueryResultsView,
|
||||||
variantAnalysisManager,
|
variantAnalysisManager,
|
||||||
evalLogViewer,
|
evalLogViewer,
|
||||||
queryStorageDir,
|
queryHistoryDirs,
|
||||||
ctx,
|
ctx,
|
||||||
queryHistoryConfigurationListener,
|
queryHistoryConfigurationListener,
|
||||||
labelProvider,
|
labelProvider,
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
export interface QueryHistoryDirs {
|
||||||
|
localQueriesDirPath: string;
|
||||||
|
variantAnalysesDirPath: string;
|
||||||
|
}
|
||||||
@@ -65,6 +65,7 @@ import { VariantAnalysisHistoryItem } from "./variant-analysis-history-item";
|
|||||||
import { getTotalResultCount } from "../variant-analysis/shared/variant-analysis";
|
import { getTotalResultCount } from "../variant-analysis/shared/variant-analysis";
|
||||||
import { HistoryTreeDataProvider } from "./history-tree-data-provider";
|
import { HistoryTreeDataProvider } from "./history-tree-data-provider";
|
||||||
import { redactableError } from "../pure/errors";
|
import { redactableError } from "../pure/errors";
|
||||||
|
import { QueryHistoryDirs } from "./query-history-dirs";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* query-history-manager.ts
|
* query-history-manager.ts
|
||||||
@@ -139,7 +140,7 @@ export class QueryHistoryManager extends DisposableObject {
|
|||||||
private readonly localQueriesResultsView: ResultsView,
|
private readonly localQueriesResultsView: ResultsView,
|
||||||
private readonly variantAnalysisManager: VariantAnalysisManager,
|
private readonly variantAnalysisManager: VariantAnalysisManager,
|
||||||
private readonly evalLogViewer: EvalLogViewer,
|
private readonly evalLogViewer: EvalLogViewer,
|
||||||
private readonly queryStorageDir: string,
|
private readonly queryHistoryDirs: QueryHistoryDirs,
|
||||||
ctx: ExtensionContext,
|
ctx: ExtensionContext,
|
||||||
private readonly queryHistoryConfigListener: QueryHistoryConfig,
|
private readonly queryHistoryConfigListener: QueryHistoryConfig,
|
||||||
private readonly labelProvider: HistoryItemLabelProvider,
|
private readonly labelProvider: HistoryItemLabelProvider,
|
||||||
@@ -389,7 +390,7 @@ export class QueryHistoryManager extends DisposableObject {
|
|||||||
ONE_HOUR_IN_MS,
|
ONE_HOUR_IN_MS,
|
||||||
TWO_HOURS_IN_MS,
|
TWO_HOURS_IN_MS,
|
||||||
queryHistoryConfigListener.ttlInMillis,
|
queryHistoryConfigListener.ttlInMillis,
|
||||||
this.queryStorageDir,
|
this.queryHistoryDirs,
|
||||||
qhm,
|
qhm,
|
||||||
ctx,
|
ctx,
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { EOL } from "os";
|
|||||||
import { join } from "path";
|
import { join } from "path";
|
||||||
import { Disposable, ExtensionContext } from "vscode";
|
import { Disposable, ExtensionContext } from "vscode";
|
||||||
import { extLogger } from "../common";
|
import { extLogger } from "../common";
|
||||||
|
import { QueryHistoryDirs } from "./query-history-dirs";
|
||||||
import { QueryHistoryManager } from "./query-history-manager";
|
import { QueryHistoryManager } from "./query-history-manager";
|
||||||
|
|
||||||
const LAST_SCRUB_TIME_KEY = "lastScrubTime";
|
const LAST_SCRUB_TIME_KEY = "lastScrubTime";
|
||||||
@@ -23,14 +24,14 @@ type Counter = {
|
|||||||
* @param wakeInterval How often to check to see if the job should run.
|
* @param wakeInterval How often to check to see if the job should run.
|
||||||
* @param throttleTime How often to actually run the job.
|
* @param throttleTime How often to actually run the job.
|
||||||
* @param maxQueryTime The maximum age of a query before is ready for deletion.
|
* @param maxQueryTime The maximum age of a query before is ready for deletion.
|
||||||
* @param queryDirectory The directory containing all queries.
|
* @param queryHistoryDirs The directories containing all query history information.
|
||||||
* @param ctx The extension context.
|
* @param ctx The extension context.
|
||||||
*/
|
*/
|
||||||
export function registerQueryHistoryScrubber(
|
export function registerQueryHistoryScrubber(
|
||||||
wakeInterval: number,
|
wakeInterval: number,
|
||||||
throttleTime: number,
|
throttleTime: number,
|
||||||
maxQueryTime: number,
|
maxQueryTime: number,
|
||||||
queryDirectory: string,
|
queryHistoryDirs: QueryHistoryDirs,
|
||||||
qhm: QueryHistoryManager,
|
qhm: QueryHistoryManager,
|
||||||
ctx: ExtensionContext,
|
ctx: ExtensionContext,
|
||||||
|
|
||||||
@@ -42,7 +43,7 @@ export function registerQueryHistoryScrubber(
|
|||||||
wakeInterval,
|
wakeInterval,
|
||||||
throttleTime,
|
throttleTime,
|
||||||
maxQueryTime,
|
maxQueryTime,
|
||||||
queryDirectory,
|
queryHistoryDirs,
|
||||||
qhm,
|
qhm,
|
||||||
ctx,
|
ctx,
|
||||||
counter,
|
counter,
|
||||||
@@ -58,7 +59,7 @@ export function registerQueryHistoryScrubber(
|
|||||||
async function scrubQueries(
|
async function scrubQueries(
|
||||||
throttleTime: number,
|
throttleTime: number,
|
||||||
maxQueryTime: number,
|
maxQueryTime: number,
|
||||||
queryDirectory: string,
|
queryHistoryDirs: QueryHistoryDirs,
|
||||||
qhm: QueryHistoryManager,
|
qhm: QueryHistoryManager,
|
||||||
ctx: ExtensionContext,
|
ctx: ExtensionContext,
|
||||||
counter?: Counter,
|
counter?: Counter,
|
||||||
@@ -75,17 +76,17 @@ async function scrubQueries(
|
|||||||
try {
|
try {
|
||||||
counter?.increment();
|
counter?.increment();
|
||||||
void extLogger.log("Scrubbing query directory. Removing old queries.");
|
void extLogger.log("Scrubbing query directory. Removing old queries.");
|
||||||
if (!(await pathExists(queryDirectory))) {
|
if (!(await pathExists(queryHistoryDirs.localQueriesDirPath))) {
|
||||||
void extLogger.log(
|
void extLogger.log(
|
||||||
`Cannot scrub. Query directory does not exist: ${queryDirectory}`,
|
`Cannot scrub. Query directory does not exist: ${queryHistoryDirs.localQueriesDirPath}`,
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const baseNames = await readdir(queryDirectory);
|
const baseNames = await readdir(queryHistoryDirs.localQueriesDirPath);
|
||||||
const errors: string[] = [];
|
const errors: string[] = [];
|
||||||
for (const baseName of baseNames) {
|
for (const baseName of baseNames) {
|
||||||
const dir = join(queryDirectory, baseName);
|
const dir = join(queryHistoryDirs.localQueriesDirPath, baseName);
|
||||||
const scrubResult = await scrubDirectory(dir, now, maxQueryTime);
|
const scrubResult = await scrubDirectory(dir, now, maxQueryTime);
|
||||||
if (scrubResult.errorMsg) {
|
if (scrubResult.errorMsg) {
|
||||||
errors.push(scrubResult.errorMsg);
|
errors.push(scrubResult.errorMsg);
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import { QueryHistoryDirs } from "../../../src/query-history/query-history-dirs";
|
||||||
|
|
||||||
|
export function createMockQueryHistoryDirs({
|
||||||
|
localQueriesDirPath = "mock-local-queries-dir-path",
|
||||||
|
variantAnalysesDirPath = "mock-variant-analyses-dir-path",
|
||||||
|
}: {
|
||||||
|
localQueriesDirPath?: string;
|
||||||
|
variantAnalysesDirPath?: string;
|
||||||
|
} = {}): QueryHistoryDirs {
|
||||||
|
return {
|
||||||
|
localQueriesDirPath,
|
||||||
|
variantAnalysesDirPath,
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -26,6 +26,7 @@ import {
|
|||||||
SortOrder,
|
SortOrder,
|
||||||
} from "../../../../src/query-history/history-tree-data-provider";
|
} from "../../../../src/query-history/history-tree-data-provider";
|
||||||
import { QueryHistoryManager } from "../../../../src/query-history/query-history-manager";
|
import { QueryHistoryManager } from "../../../../src/query-history/query-history-manager";
|
||||||
|
import { createMockQueryHistoryDirs } from "../../../factories/query-history/query-history-dirs";
|
||||||
|
|
||||||
describe("HistoryTreeDataProvider", () => {
|
describe("HistoryTreeDataProvider", () => {
|
||||||
const mockExtensionLocation = join(tmpDir.name, "mock-extension-location");
|
const mockExtensionLocation = join(tmpDir.name, "mock-extension-location");
|
||||||
@@ -425,7 +426,7 @@ describe("HistoryTreeDataProvider", () => {
|
|||||||
localQueriesResultsViewStub,
|
localQueriesResultsViewStub,
|
||||||
variantAnalysisManagerStub,
|
variantAnalysisManagerStub,
|
||||||
{} as EvalLogViewer,
|
{} as EvalLogViewer,
|
||||||
"xxx",
|
createMockQueryHistoryDirs(),
|
||||||
{
|
{
|
||||||
globalStorageUri: vscode.Uri.file(mockExtensionLocation),
|
globalStorageUri: vscode.Uri.file(mockExtensionLocation),
|
||||||
extensionPath: vscode.Uri.file("/x/y/z").fsPath,
|
extensionPath: vscode.Uri.file("/x/y/z").fsPath,
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import { QuickPickItem, TextEditor } from "vscode";
|
|||||||
import { WebviewReveal } from "../../../../src/interface-utils";
|
import { WebviewReveal } from "../../../../src/interface-utils";
|
||||||
import * as helpers from "../../../../src/helpers";
|
import * as helpers from "../../../../src/helpers";
|
||||||
import { mockedObject } from "../../utils/mocking.helpers";
|
import { mockedObject } from "../../utils/mocking.helpers";
|
||||||
|
import { createMockQueryHistoryDirs } from "../../../factories/query-history/query-history-dirs";
|
||||||
|
|
||||||
describe("QueryHistoryManager", () => {
|
describe("QueryHistoryManager", () => {
|
||||||
const mockExtensionLocation = join(tmpDir.name, "mock-extension-location");
|
const mockExtensionLocation = join(tmpDir.name, "mock-extension-location");
|
||||||
@@ -1150,7 +1151,7 @@ describe("QueryHistoryManager", () => {
|
|||||||
localQueriesResultsViewStub,
|
localQueriesResultsViewStub,
|
||||||
variantAnalysisManagerStub,
|
variantAnalysisManagerStub,
|
||||||
{} as EvalLogViewer,
|
{} as EvalLogViewer,
|
||||||
"xxx",
|
createMockQueryHistoryDirs(),
|
||||||
{
|
{
|
||||||
globalStorageUri: vscode.Uri.file(mockExtensionLocation),
|
globalStorageUri: vscode.Uri.file(mockExtensionLocation),
|
||||||
extensionPath: vscode.Uri.file("/x/y/z").fsPath,
|
extensionPath: vscode.Uri.file("/x/y/z").fsPath,
|
||||||
|
|||||||
@@ -181,7 +181,7 @@ describe("query history scrubber", () => {
|
|||||||
ONE_HOUR_IN_MS,
|
ONE_HOUR_IN_MS,
|
||||||
TWO_HOURS_IN_MS,
|
TWO_HOURS_IN_MS,
|
||||||
LESS_THAN_ONE_DAY,
|
LESS_THAN_ONE_DAY,
|
||||||
dir,
|
{ localQueriesDirPath: dir, variantAnalysesDirPath: dir },
|
||||||
mockedObject<QueryHistoryManager>({
|
mockedObject<QueryHistoryManager>({
|
||||||
removeDeletedQueries: () => {
|
removeDeletedQueries: () => {
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import { QueryRunner } from "../../../../src/queryRunner";
|
|||||||
import { VariantAnalysisManager } from "../../../../src/variant-analysis/variant-analysis-manager";
|
import { VariantAnalysisManager } from "../../../../src/variant-analysis/variant-analysis-manager";
|
||||||
import { QueryHistoryManager } from "../../../../src/query-history/query-history-manager";
|
import { QueryHistoryManager } from "../../../../src/query-history/query-history-manager";
|
||||||
import { mockedObject } from "../../utils/mocking.helpers";
|
import { mockedObject } from "../../utils/mocking.helpers";
|
||||||
|
import { createMockQueryHistoryDirs } from "../../../factories/query-history/query-history-dirs";
|
||||||
|
|
||||||
// set a higher timeout since recursive delete may take a while, expecially on Windows.
|
// set a higher timeout since recursive delete may take a while, expecially on Windows.
|
||||||
jest.setTimeout(120000);
|
jest.setTimeout(120000);
|
||||||
@@ -74,7 +75,7 @@ describe("Variant Analyses and QueryHistoryManager", () => {
|
|||||||
localQueriesResultsViewStub,
|
localQueriesResultsViewStub,
|
||||||
variantAnalysisManagerStub,
|
variantAnalysisManagerStub,
|
||||||
{} as EvalLogViewer,
|
{} as EvalLogViewer,
|
||||||
STORAGE_DIR,
|
createMockQueryHistoryDirs({ localQueriesDirPath: STORAGE_DIR }),
|
||||||
mockedObject<ExtensionContext>({
|
mockedObject<ExtensionContext>({
|
||||||
globalStorageUri: Uri.file(STORAGE_DIR),
|
globalStorageUri: Uri.file(STORAGE_DIR),
|
||||||
storageUri: undefined,
|
storageUri: undefined,
|
||||||
|
|||||||
Reference in New Issue
Block a user