-
Notifications
You must be signed in to change notification settings - Fork 226
Add "CodeQL: Trim Cache" using new mode parameter of evaluation/clearCache
#2931
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,6 +29,35 @@ export interface ClearCacheParams { | |
| * Whether the cache should actually be cleared. | ||
| */ | ||
| dryRun: boolean; | ||
| /** | ||
| * The mode to use when trimming the disk cache. | ||
| */ | ||
| mode?: CacheTrimmingMode; | ||
| } | ||
|
|
||
| export type CacheTrimmingMode = number; | ||
| /** | ||
| * The mode to use when trimming the disk cache. This namespace is intentionally not an enum, see | ||
| * "for the sake of extensibility" comment above. | ||
| */ | ||
| // eslint-disable-next-line @typescript-eslint/no-namespace | ||
| export namespace CacheTrimmingMode { | ||
| /** The entire cache is deleted unconditionally. */ | ||
| export const BRUTAL = 0; | ||
| /** Only `cached` predicates are kept. */ | ||
| export const NORMAL = 1; | ||
| /** | ||
| * Trim the cache down to the configured size, but *within* this limit keep anything that | ||
| * appears to be even possibly potentially useful in the future. | ||
| */ | ||
| export const LIGHT = 2; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are there plans to support
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably not, as they're pretty obscure and there's little practical reason to support them in VSCode. Also, we're renaming "brutal" → "clear" and "normal" → "trim" to be more in line with the VSCode commands, so if you have suggestions on new names for "light" and "gentle", I'm all ears :) |
||
| /** | ||
| * As {@link LIGHT}, but only if the *currently active* backend has written anything to | ||
| * the cache in its lifetime. (Thus it doesn't make much sense to specify this in a stand-alone | ||
| * CLI invocation, but we do it as a separate operation before shutting down a query server, | ||
| * because it can then have its own timeout). | ||
| */ | ||
| export const GENTLE = 3; | ||
| } | ||
|
|
||
| /** | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ import { DatabaseItem } from "../databases/local-databases"; | |
| import { | ||
| clearCache, | ||
| ClearCacheParams, | ||
| CacheTrimmingMode, | ||
| clearPackCache, | ||
| deregisterDatabases, | ||
| registerDatabases, | ||
|
|
@@ -57,15 +58,20 @@ export class NewQueryRunner extends QueryRunner { | |
| async clearCacheInDatabase( | ||
| dbItem: DatabaseItem, | ||
| token: CancellationToken, | ||
| mode: "trim" | "clear", | ||
| ): Promise<void> { | ||
| if (dbItem.contents === undefined) { | ||
| throw new Error("Can't clear the cache in an invalid database."); | ||
| throw new Error(`Can't ${mode} the cache in an invalid database.`); | ||
| } | ||
|
|
||
| const db = dbItem.databaseUri.fsPath; | ||
| const params: ClearCacheParams = { | ||
| dryRun: false, | ||
| db, | ||
| mode: { | ||
| trim: CacheTrimmingMode.NORMAL, | ||
| clear: CacheTrimmingMode.BRUTAL, | ||
| }[mode], | ||
|
Comment on lines
+71
to
+74
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor: could you extract this to a function? I find this hard to read. |
||
| }; | ||
| await this.qs.sendRequest(clearCache, params, token); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to extract
"trim" | "clear"into atypeso it can be reused below.