Add "VSCode: Trim Cache" command that calls evaluation/trimCache
The purpose of this change is to add a command that clears the cache except for predicates marked `cached`. In contrast, the existing "VSCode: Clear Cache" command clears everything (`--mode=brutal`). This calls into the query server's `evaluation/trimCache` method; however, its existing behaviour is to do a database cleanup with `--mode=gentle`. This is not well documented, and `--mode=normal` would give the desired behaviour. Accordingly, this approach is dependent on separately changing the backend behaviour to `--mode=normal`. Other possible amendments to this commit would be to not touch the legacy client (replacing required methods by failing promises, since the legacy server is fully deprecated already), or to have less duplication (by introducing more arguments — however, I'm applying the rule of thumb that >3 copy-pastes are required for the introduction of a deduplicating abstraction).
This commit is contained in:
@@ -712,6 +712,10 @@
|
||||
"command": "codeQL.clearCache",
|
||||
"title": "CodeQL: Clear Cache"
|
||||
},
|
||||
{
|
||||
"command": "codeQL.trimCache",
|
||||
"title": "CodeQL: Trim Cache"
|
||||
},
|
||||
{
|
||||
"command": "codeQL.installPackDependencies",
|
||||
"title": "CodeQL: Install Pack Dependencies"
|
||||
|
||||
@@ -207,6 +207,7 @@ export type LocalDatabasesCommands = {
|
||||
"codeQL.chooseDatabaseGithub": () => Promise<void>;
|
||||
"codeQL.upgradeCurrentDatabase": () => Promise<void>;
|
||||
"codeQL.clearCache": () => Promise<void>;
|
||||
"codeQL.trimCache": () => Promise<void>;
|
||||
|
||||
// Explorer context menu
|
||||
"codeQL.setCurrentDatabase": (uri: Uri) => Promise<void>;
|
||||
|
||||
@@ -252,6 +252,7 @@ export class DatabaseUI extends DisposableObject {
|
||||
"codeQL.upgradeCurrentDatabase":
|
||||
this.handleUpgradeCurrentDatabase.bind(this),
|
||||
"codeQL.clearCache": this.handleClearCache.bind(this),
|
||||
"codeQL.trimCache": this.handleTrimCache.bind(this),
|
||||
"codeQLDatabases.chooseDatabaseFolder":
|
||||
this.handleChooseDatabaseFolder.bind(this),
|
||||
"codeQLDatabases.chooseDatabaseArchive":
|
||||
@@ -703,6 +704,25 @@ export class DatabaseUI extends DisposableObject {
|
||||
);
|
||||
}
|
||||
|
||||
private async handleTrimCache(): Promise<void> {
|
||||
return withProgress(
|
||||
async (_progress, token) => {
|
||||
if (
|
||||
this.queryServer !== undefined &&
|
||||
this.databaseManager.currentDatabaseItem !== undefined
|
||||
) {
|
||||
await this.queryServer.trimCacheInDatabase(
|
||||
this.databaseManager.currentDatabaseItem,
|
||||
token,
|
||||
);
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "Trimming cache",
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
private async handleGetCurrentDatabase(): Promise<string | undefined> {
|
||||
const dbItem = await this.getDatabaseItemInternal(undefined);
|
||||
return dbItem?.databaseUri.fsPath;
|
||||
|
||||
@@ -53,6 +53,7 @@ export class LegacyQueryRunner extends QueryRunner {
|
||||
) {
|
||||
this.qs.onDidStartQueryServer(callBack);
|
||||
}
|
||||
|
||||
async clearCacheInDatabase(
|
||||
dbItem: DatabaseItem,
|
||||
token: CancellationToken,
|
||||
@@ -60,6 +61,15 @@ export class LegacyQueryRunner extends QueryRunner {
|
||||
await clearCacheInDatabase(this.qs, dbItem, token);
|
||||
}
|
||||
|
||||
async trimCacheInDatabase(
|
||||
dbItem: DatabaseItem,
|
||||
token: CancellationToken,
|
||||
): Promise<void> {
|
||||
// For the sake of conforming to the QueryRunner interface, delegate to clearCacheInDatabase
|
||||
// just for the effect of getting a legacy query server deprecation error response.
|
||||
await clearCacheInDatabase(this.qs, dbItem, token);
|
||||
}
|
||||
|
||||
public async compileAndRunQueryAgainstDatabaseCore(
|
||||
dbPath: string,
|
||||
query: CoreQueryTarget,
|
||||
|
||||
@@ -10,6 +10,8 @@ import {
|
||||
clearPackCache,
|
||||
deregisterDatabases,
|
||||
registerDatabases,
|
||||
trimCache,
|
||||
TrimCacheParams,
|
||||
upgradeDatabase,
|
||||
} from "./new-messages";
|
||||
import { CoreQueryResults, CoreQueryTarget, QueryRunner } from "./query-runner";
|
||||
@@ -70,6 +72,21 @@ export class NewQueryRunner extends QueryRunner {
|
||||
await this.qs.sendRequest(clearCache, params, token);
|
||||
}
|
||||
|
||||
async trimCacheInDatabase(
|
||||
dbItem: DatabaseItem,
|
||||
token: CancellationToken,
|
||||
): Promise<void> {
|
||||
if (dbItem.contents === undefined) {
|
||||
throw new Error("Can't trim the cache in an invalid database.");
|
||||
}
|
||||
|
||||
const db = dbItem.databaseUri.fsPath;
|
||||
const params: TrimCacheParams = {
|
||||
db,
|
||||
};
|
||||
await this.qs.sendRequest(trimCache, params, token);
|
||||
}
|
||||
|
||||
public async compileAndRunQueryAgainstDatabaseCore(
|
||||
dbPath: string,
|
||||
query: CoreQueryTarget,
|
||||
|
||||
@@ -67,6 +67,11 @@ export abstract class QueryRunner {
|
||||
token: CancellationToken,
|
||||
): Promise<void>;
|
||||
|
||||
abstract trimCacheInDatabase(
|
||||
dbItem: DatabaseItem,
|
||||
token: CancellationToken,
|
||||
): Promise<void>;
|
||||
|
||||
/**
|
||||
* Overridden in subclasses to evaluate the query via the query server and return the results.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user