Skip to content
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

Add "CodeQL: Trim Cache" using new mode parameter of evaluation/clearCache #2931

Closed
wants to merge 1 commit into from

Conversation

d10c
Copy link
Contributor

@d10c d10c commented Oct 9, 2023

The purpose of this change is to add a command to clear the cache
except for cached predicates. This is the
same behaviour as codeql database cleanup --mode=normal.
In contrast, the existing "CodeQL: Clear Cache" corresponds to --mode=brutal.

This change depends on adding a new mode parameter to the
evaluation/clearCache method of the query server. This is the same
method that the existing "CodeQL: Clear Cache" command targets, which means
that this solution will not fail when used with older query servers
but will have the same behaviour as the existing command.
This somewhat decouples the release process of the VSCode extension and
the CodeQL release.

Testing done so far: manual (VSCode extension debug run). I haven't seen
automated tests for the other command either.

As part of adding the new "mode" parameter to the clearCache method, the
official query server spec will need to be updated to match new-messages.ts
here.

Checklist

  • CHANGELOG.md has been updated to incorporate all user visible changes made by this pull request.
  • Issues have been created for any UI or other user-facing changes made by this pull request.
  • [Maintainers only] If this pull request makes user-facing changes that require documentation changes, open a corresponding docs pull request in the github/codeql repo and add the ready-for-doc-review label there.

…rCache`

The purpose of this change is to add a command to clear the cache
except for `cached` predicates. This is the
same behaviour as `codeql database cleanup --mode=normal`.
In contrast, the existing "CodeQL: Clear Cache" corresponds to `--mode=brutal`.

This change depends on adding a new `mode` parameter to the
`evaluation/clearCache` method of the query server. This is the same
method that the existing "CodeQL: Clear Cache" command targets, which means
that this solution will not fail when used with older query servers
but will have the same behaviour as the existing command.
This somewhat decouples the release process of the VSCode extension and
the CodeQL release.

Testing done so far: manual (VSCode extension debug run). I haven't seen
automated tests for the other command either.

As part of adding the new "mode" parameter to the clearCache method, the
official query server spec will need to be updated to match `new-messages.ts`
here.
Copy link
Contributor

@aeisenberg aeisenberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable. I have a couple of minor suggestions.

@@ -684,7 +685,7 @@ export class DatabaseUI extends DisposableObject {
);
}

private async handleClearCache(): Promise<void> {
private async handleClearCache(mode: "trim" | "clear"): Promise<void> {
Copy link
Contributor

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 a type so it can be reused below.

* 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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there plans to support LIGHT and GENTLE in the future?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 :)

Comment on lines +71 to +74
mode: {
trim: CacheTrimmingMode.NORMAL,
clear: CacheTrimmingMode.BRUTAL,
}[mode],
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

@d10c
Copy link
Contributor Author

d10c commented Oct 11, 2023

Closing this PR in favour of the approach taken in #2928

@d10c d10c closed this Oct 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants