Skip to content

Commit a59f3c9

Browse files
committed
Add "CodeQL: Trim Overlay Base Cache" command
1 parent eb44a90 commit a59f3c9

File tree

5 files changed

+72
-0
lines changed

5 files changed

+72
-0
lines changed

extensions/ql-vscode/package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,10 @@
790790
"command": "codeQL.trimCache",
791791
"title": "CodeQL: Trim Cache"
792792
},
793+
{
794+
"command": "codeQL.trimOverlayBaseCache",
795+
"title": "CodeQL: Trim Overlay Base Cache"
796+
},
793797
{
794798
"command": "codeQL.installPackDependencies",
795799
"title": "CodeQL: Install Pack Dependencies"
@@ -1817,6 +1821,10 @@
18171821
},
18181822
{
18191823
"command": "codeQL.trimCache"
1824+
},
1825+
{
1826+
"command": "codeQL.trimOverlayBaseCache",
1827+
"when": "codeQL.cliFeatures.queryServerTrimCacheWithMode"
18201828
}
18211829
],
18221830
"editor/context": [

extensions/ql-vscode/src/common/commands.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ export type LocalDatabasesCommands = {
221221
"codeQL.upgradeCurrentDatabase": () => Promise<void>;
222222
"codeQL.clearCache": () => Promise<void>;
223223
"codeQL.trimCache": () => Promise<void>;
224+
"codeQL.trimOverlayBaseCache": () => Promise<void>;
224225

225226
// Explorer context menu
226227
"codeQL.setCurrentDatabase": (uri: Uri) => Promise<void>;

extensions/ql-vscode/src/databases/local-databases-ui.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ export class DatabaseUI extends DisposableObject {
284284
this.handleUpgradeCurrentDatabase.bind(this),
285285
"codeQL.clearCache": this.handleClearCache.bind(this),
286286
"codeQL.trimCache": this.handleTrimCache.bind(this),
287+
"codeQL.trimOverlayBaseCache": this.handleTrimOverlayBaseCache.bind(this),
287288
"codeQLDatabases.chooseDatabaseFolder":
288289
this.handleChooseDatabaseFolder.bind(this),
289290
"codeQLDatabases.chooseDatabaseArchive":
@@ -688,6 +689,25 @@ export class DatabaseUI extends DisposableObject {
688689
);
689690
}
690691

692+
private async handleTrimOverlayBaseCache(): Promise<void> {
693+
return withProgress(
694+
async () => {
695+
if (
696+
this.queryServer !== undefined &&
697+
this.databaseManager.currentDatabaseItem !== undefined
698+
) {
699+
await this.queryServer.trimCacheWithModeInDatabase(
700+
this.databaseManager.currentDatabaseItem,
701+
"overlay",
702+
);
703+
}
704+
},
705+
{
706+
title: "Removing all overlay-dependent data from cache",
707+
},
708+
);
709+
}
710+
691711
private async handleGetCurrentDatabase(): Promise<string | undefined> {
692712
const dbItem = await this.getDatabaseItemInternal(undefined);
693713
return dbItem?.databaseUri.fsPath;

extensions/ql-vscode/src/query-server/messages.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,22 @@ export interface TrimCacheParams {
4242
db: string;
4343
}
4444

45+
/**
46+
* Parameters for trimming the cache of a dataset with a specific mode.
47+
*/
48+
export interface TrimCacheWithModeParams {
49+
/**
50+
* The dataset that we want to trim the cache of.
51+
*/
52+
db: string;
53+
/**
54+
* The cache cleanup mode to use.
55+
*/
56+
mode: ClearCacheMode;
57+
}
58+
59+
export type ClearCacheMode = "clear" | "trim" | "fit" | "overlay";
60+
4561
/**
4662
* The result of trimming or clearing the cache.
4763
*/
@@ -193,6 +209,14 @@ export const trimCache = new RequestType<
193209
ClearCacheResult,
194210
void
195211
>("evaluation/trimCache");
212+
/**
213+
* Trim the cache of a dataset with a specific mode.
214+
*/
215+
export const trimCacheWithMode = new RequestType<
216+
WithProgressId<TrimCacheWithModeParams>,
217+
ClearCacheResult,
218+
void
219+
>("evaluation/trimCacheWithMode");
196220

197221
/**
198222
* Clear the pack cache

extensions/ql-vscode/src/query-server/query-runner.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,20 @@ import { UserCancellationException } from "../common/vscode/progress";
66
import type { DatabaseItem } from "../databases/local-databases/database-item";
77
import { QueryOutputDir } from "../local-queries/query-output-dir";
88
import type {
9+
ClearCacheMode,
910
ClearCacheParams,
1011
Position,
1112
QueryResultType,
1213
TrimCacheParams,
14+
TrimCacheWithModeParams,
1315
} from "./messages";
1416
import {
1517
clearCache,
1618
clearPackCache,
1719
deregisterDatabases,
1820
registerDatabases,
1921
trimCache,
22+
trimCacheWithMode,
2023
upgradeDatabase,
2124
} from "./messages";
2225
import type { BaseLogger, Logger } from "../common/logging";
@@ -142,6 +145,22 @@ export class QueryRunner {
142145
await this.qs.sendRequest(trimCache, params);
143146
}
144147

148+
async trimCacheWithModeInDatabase(
149+
dbItem: DatabaseItem,
150+
mode: ClearCacheMode,
151+
): Promise<void> {
152+
if (dbItem.contents === undefined) {
153+
throw new Error("Can't clean the cache in an invalid database.");
154+
}
155+
156+
const db = dbItem.databaseUri.fsPath;
157+
const params: TrimCacheWithModeParams = {
158+
db,
159+
mode,
160+
};
161+
await this.qs.sendRequest(trimCacheWithMode, params);
162+
}
163+
145164
public async compileAndRunQueryAgainstDatabaseCore(
146165
dbPath: string,
147166
queries: CoreQueryTarget[],

0 commit comments

Comments
 (0)