Skip to content

Commit 06463a2

Browse files
committed
Clean up variant analyses directory
1 parent 7b2ef6b commit 06463a2

File tree

3 files changed

+42
-6
lines changed

3 files changed

+42
-6
lines changed

extensions/ql-vscode/src/pure/files.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,8 @@ export function pathsEqual(
6767
}
6868
return path1 === path2;
6969
}
70+
71+
export async function readDirFullPaths(path: string): Promise<string[]> {
72+
const baseNames = await readdir(path);
73+
return baseNames.map((baseName) => join(path, baseName));
74+
}

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

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { pathExists, readdir, stat, remove, readFile } from "fs-extra";
1+
import { pathExists, stat, remove, readFile } from "fs-extra";
22
import { EOL } from "os";
33
import { join } from "path";
44
import { Disposable, ExtensionContext } from "vscode";
55
import { extLogger } from "../common";
6+
import { readDirFullPaths } from "../pure/files";
67
import { QueryHistoryDirs } from "./query-history-dirs";
78
import { QueryHistoryManager } from "./query-history-manager";
89

@@ -75,18 +76,33 @@ async function scrubQueries(
7576
let scrubCount = 0; // total number of directories deleted
7677
try {
7778
counter?.increment();
78-
void extLogger.log("Scrubbing query directory. Removing old queries.");
79+
void extLogger.log(
80+
"Cleaning up query history directories. Removing old entries.",
81+
);
82+
7983
if (!(await pathExists(queryHistoryDirs.localQueriesDirPath))) {
8084
void extLogger.log(
81-
`Cannot scrub. Query directory does not exist: ${queryHistoryDirs.localQueriesDirPath}`,
85+
`Cannot clean up query history directories. Local queries directory does not exist: ${queryHistoryDirs.localQueriesDirPath}`,
86+
);
87+
return;
88+
}
89+
if (!(await pathExists(queryHistoryDirs.variantAnalysesDirPath))) {
90+
void extLogger.log(
91+
`Cannot clean up query history directories. Variant analyses directory does not exist: ${queryHistoryDirs.variantAnalysesDirPath}`,
8292
);
8393
return;
8494
}
8595

86-
const baseNames = await readdir(queryHistoryDirs.localQueriesDirPath);
96+
const localQueryDirPaths = await readDirFullPaths(
97+
queryHistoryDirs.localQueriesDirPath,
98+
);
99+
const variantAnalysisDirPaths = await readDirFullPaths(
100+
queryHistoryDirs.variantAnalysesDirPath,
101+
);
102+
const allDirPaths = [...localQueryDirPaths, ...variantAnalysisDirPaths];
103+
87104
const errors: string[] = [];
88-
for (const baseName of baseNames) {
89-
const dir = join(queryHistoryDirs.localQueriesDirPath, baseName);
105+
for (const dir of allDirPaths) {
90106
const scrubResult = await scrubDirectory(dir, now, maxQueryTime);
91107
if (scrubResult.errorMsg) {
92108
errors.push(scrubResult.errorMsg);

extensions/ql-vscode/test/unit-tests/pure/files.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
gatherQlFiles,
55
getDirectoryNamesInsidePath,
66
pathsEqual,
7+
readDirFullPaths,
78
} from "../../../src/pure/files";
89

910
describe("files", () => {
@@ -100,6 +101,20 @@ describe("files", () => {
100101
expect(result).toEqual(["sub-folder"]);
101102
});
102103
});
104+
105+
describe("readDirFullPaths", () => {
106+
it("should return all files with full path", async () => {
107+
const file1 = join(dataDir, "compute-default-strings.ql");
108+
const file2 = join(dataDir, "multiple-result-sets.ql");
109+
const file3 = join(dataDir, "query.ql");
110+
111+
const paths = await readDirFullPaths(dataDir);
112+
113+
expect(paths.some((path) => path === file1)).toBe(true);
114+
expect(paths.some((path) => path === file2)).toBe(true);
115+
expect(paths.some((path) => path === file3)).toBe(true);
116+
});
117+
});
103118
});
104119

105120
describe("pathsEqual", () => {

0 commit comments

Comments
 (0)