1- import { pathExists , readdir , stat , remove , readFile } from "fs-extra" ;
1+ import { pathExists , stat , remove , readFile } from "fs-extra" ;
22import { EOL } from "os" ;
33import { join } from "path" ;
44import { Disposable , ExtensionContext } from "vscode" ;
55import { extLogger } from "../common" ;
6+ import { readDirFullPaths } from "../pure/files" ;
7+ import { QueryHistoryDirs } from "./query-history-dirs" ;
68import { QueryHistoryManager } from "./query-history-manager" ;
79
810const LAST_SCRUB_TIME_KEY = "lastScrubTime" ;
@@ -23,14 +25,14 @@ type Counter = {
2325 * @param wakeInterval How often to check to see if the job should run.
2426 * @param throttleTime How often to actually run the job.
2527 * @param maxQueryTime The maximum age of a query before is ready for deletion.
26- * @param queryDirectory The directory containing all queries .
28+ * @param queryHistoryDirs The directories containing all query history information .
2729 * @param ctx The extension context.
2830 */
2931export function registerQueryHistoryScrubber (
3032 wakeInterval : number ,
3133 throttleTime : number ,
3234 maxQueryTime : number ,
33- queryDirectory : string ,
35+ queryHistoryDirs : QueryHistoryDirs ,
3436 qhm : QueryHistoryManager ,
3537 ctx : ExtensionContext ,
3638
@@ -42,7 +44,7 @@ export function registerQueryHistoryScrubber(
4244 wakeInterval ,
4345 throttleTime ,
4446 maxQueryTime ,
45- queryDirectory ,
47+ queryHistoryDirs ,
4648 qhm ,
4749 ctx ,
4850 counter ,
@@ -58,7 +60,7 @@ export function registerQueryHistoryScrubber(
5860async function scrubQueries (
5961 throttleTime : number ,
6062 maxQueryTime : number ,
61- queryDirectory : string ,
63+ queryHistoryDirs : QueryHistoryDirs ,
6264 qhm : QueryHistoryManager ,
6365 ctx : ExtensionContext ,
6466 counter ?: Counter ,
@@ -74,18 +76,33 @@ async function scrubQueries(
7476 let scrubCount = 0 ; // total number of directories deleted
7577 try {
7678 counter ?. increment ( ) ;
77- void extLogger . log ( "Scrubbing query directory. Removing old queries." ) ;
78- if ( ! ( await pathExists ( queryDirectory ) ) ) {
79+ void extLogger . log (
80+ "Cleaning up query history directories. Removing old entries." ,
81+ ) ;
82+
83+ if ( ! ( await pathExists ( queryHistoryDirs . localQueriesDirPath ) ) ) {
84+ void extLogger . log (
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 ) ) ) {
7990 void extLogger . log (
80- `Cannot scrub. Query directory does not exist: ${ queryDirectory } ` ,
91+ `Cannot clean up query history directories. Variant analyses directory does not exist: ${ queryHistoryDirs . variantAnalysesDirPath } ` ,
8192 ) ;
8293 return ;
8394 }
8495
85- const baseNames = await readdir ( queryDirectory ) ;
96+ const localQueryDirPaths = await readDirFullPaths (
97+ queryHistoryDirs . localQueriesDirPath ,
98+ ) ;
99+ const variantAnalysisDirPaths = await readDirFullPaths (
100+ queryHistoryDirs . variantAnalysesDirPath ,
101+ ) ;
102+ const allDirPaths = [ ...localQueryDirPaths , ...variantAnalysisDirPaths ] ;
103+
86104 const errors : string [ ] = [ ] ;
87- for ( const baseName of baseNames ) {
88- const dir = join ( queryDirectory , baseName ) ;
105+ for ( const dir of allDirPaths ) {
89106 const scrubResult = await scrubDirectory ( dir , now , maxQueryTime ) ;
90107 if ( scrubResult . errorMsg ) {
91108 errors . push ( scrubResult . errorMsg ) ;
0 commit comments