Merge pull request #2928 from github/d10c/trim-cache-command
Add "CodeQL: Trim Cache" command that calls `evaluation/trimCache`
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
- Increase the required version of VS Code to 1.82.0. [#2877](https://github.com/github/vscode-codeql/pull/2877)
|
||||
- Fix a bug where the query server was restarted twice after configuration changes. [#2884](https://github.com/github/vscode-codeql/pull/2884).
|
||||
- Add support for the `telemetry.telemetryLevel` setting. For more information, see the [telemetry documentation](https://codeql.github.com/docs/codeql-for-visual-studio-code/about-telemetry-in-codeql-for-visual-studio-code). [#2824](https://github.com/github/vscode-codeql/pull/2824).
|
||||
- Add a "CodeQL: Trim Cache" command that clears the evaluation cache of a database except for predicates annotated with the `cached` keyword. Its purpose is to get accurate performance measurements when tuning the final stage of a query, like a data-flow configuration. This is equivalent to the `codeql database cleanup --mode=normal` CLI command. In contrast, the existing "CodeQL: Clear Cache" command clears the entire cache. CodeQL CLI v2.15.1 or later is required. [#2928](https://github.com/github/vscode-codeql/pull/2928)
|
||||
- Fix syntax highlighting directly after import statements with instantiation arguments. [#2792](https://github.com/github/vscode-codeql/pull/2792)
|
||||
- The `debug.saveBeforeStart` setting is now respected when running variant analyses. [#2950](https://github.com/github/vscode-codeql/pull/2950)
|
||||
- The 'open database' button of the model editor was renamed to 'open source'. Also, it's now only available if the source archive is available as a workspace folder. [#2945](https://github.com/github/vscode-codeql/pull/2945)
|
||||
|
||||
@@ -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"
|
||||
@@ -1806,6 +1810,10 @@
|
||||
{
|
||||
"command": "codeQL.gotoQLContextEditor",
|
||||
"when": "false"
|
||||
},
|
||||
{
|
||||
"command": "codeQL.trimCache",
|
||||
"when": "codeql.supportsTrimCache"
|
||||
}
|
||||
],
|
||||
"editor/context": [
|
||||
|
||||
@@ -1492,6 +1492,13 @@ export class CodeQLCliServer implements Disposable {
|
||||
CliVersionConstraint.CLI_VERSION_WITH_QUICK_EVAL_COUNT,
|
||||
) >= 0,
|
||||
);
|
||||
await this.app.commands.execute(
|
||||
"setContext",
|
||||
"codeql.supportsTrimCache",
|
||||
newVersion.compare(
|
||||
CliVersionConstraint.CLI_VERSION_WITH_TRIM_CACHE,
|
||||
) >= 0,
|
||||
);
|
||||
} catch (e) {
|
||||
this._versionChangedListeners.forEach((listener) =>
|
||||
listener(undefined),
|
||||
@@ -1755,6 +1762,12 @@ export class CliVersionConstraint {
|
||||
"2.14.0",
|
||||
);
|
||||
|
||||
/**
|
||||
* CLI version where the query server supports the `evaluation/trimCache` method
|
||||
* with `codeql database cleanup --mode=trim` semantics.
|
||||
*/
|
||||
public static CLI_VERSION_WITH_TRIM_CACHE = new SemVer("2.15.1");
|
||||
|
||||
constructor(private readonly cli: CodeQLCliServer) {
|
||||
/**/
|
||||
}
|
||||
|
||||
@@ -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