Skip to content

Commit 82df605

Browse files
committed
Add "CodeQL: Trim Overlay Base Cache" command
1 parent cc86563 commit 82df605

File tree

5 files changed

+47
-0
lines changed

5 files changed

+47
-0
lines changed

extensions/ql-vscode/package.json

Lines changed: 4 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"

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: 19 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,24 @@ 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.trimOverlayBaseCacheInDatabase(
700+
this.databaseManager.currentDatabaseItem,
701+
);
702+
}
703+
},
704+
{
705+
title: "Removing all overlay-dependent data from cache",
706+
},
707+
);
708+
}
709+
691710
private async handleGetCurrentDatabase(): Promise<string | undefined> {
692711
const dbItem = await this.getDatabaseItemInternal(undefined);
693712
return dbItem?.databaseUri.fsPath;

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,14 @@ export const trimCache = new RequestType<
193193
ClearCacheResult,
194194
void
195195
>("evaluation/trimCache");
196+
/**
197+
* Trim the cache of a dataset
198+
*/
199+
export const trimOverlayBaseCache = new RequestType<
200+
WithProgressId<TrimCacheParams>,
201+
ClearCacheResult,
202+
void
203+
>("evaluation/trimOverlayBaseCache");
196204

197205
/**
198206
* Clear the pack cache

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
deregisterDatabases,
1818
registerDatabases,
1919
trimCache,
20+
trimOverlayBaseCache,
2021
upgradeDatabase,
2122
} from "./messages";
2223
import type { BaseLogger, Logger } from "../common/logging";
@@ -142,6 +143,20 @@ export class QueryRunner {
142143
await this.qs.sendRequest(trimCache, params);
143144
}
144145

146+
async trimOverlayBaseCacheInDatabase(dbItem: DatabaseItem): Promise<void> {
147+
if (dbItem.contents === undefined) {
148+
throw new Error(
149+
"Can't trim the overlay base cache in an invalid database.",
150+
);
151+
}
152+
153+
const db = dbItem.databaseUri.fsPath;
154+
const params: TrimCacheParams = {
155+
db,
156+
};
157+
await this.qs.sendRequest(trimOverlayBaseCache, params);
158+
}
159+
145160
public async compileAndRunQueryAgainstDatabaseCore(
146161
dbPath: string,
147162
queries: CoreQueryTarget[],

0 commit comments

Comments
 (0)