File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 721721 "command" : " codeQL.clearCache" ,
722722 "title" : " CodeQL: Clear Cache"
723723 },
724+ {
725+ "command" : " codeQL.trimCache" ,
726+ "title" : " CodeQL: Trim Cache"
727+ },
724728 {
725729 "command" : " codeQL.installPackDependencies" ,
726730 "title" : " CodeQL: Install Pack Dependencies"
Original file line number Diff line number Diff line change @@ -208,6 +208,7 @@ export type LocalDatabasesCommands = {
208208 "codeQL.chooseDatabaseGithub" : ( ) => Promise < void > ;
209209 "codeQL.upgradeCurrentDatabase" : ( ) => Promise < void > ;
210210 "codeQL.clearCache" : ( ) => Promise < void > ;
211+ "codeQL.trimCache" : ( ) => Promise < void > ;
211212
212213 // Explorer context menu
213214 "codeQL.setCurrentDatabase" : ( uri : Uri ) => Promise < void > ;
Original file line number Diff line number Diff line change @@ -252,6 +252,7 @@ export class DatabaseUI extends DisposableObject {
252252 "codeQL.upgradeCurrentDatabase" :
253253 this . handleUpgradeCurrentDatabase . bind ( this ) ,
254254 "codeQL.clearCache" : this . handleClearCache . bind ( this ) ,
255+ "codeQL.trimCache" : this . handleTrimCache . bind ( this ) ,
255256 "codeQLDatabases.chooseDatabaseFolder" :
256257 this . handleChooseDatabaseFolder . bind ( this ) ,
257258 "codeQLDatabases.chooseDatabaseArchive" :
@@ -703,6 +704,25 @@ export class DatabaseUI extends DisposableObject {
703704 ) ;
704705 }
705706
707+ private async handleTrimCache ( ) : Promise < void > {
708+ return withProgress (
709+ async ( _progress , token ) => {
710+ if (
711+ this . queryServer !== undefined &&
712+ this . databaseManager . currentDatabaseItem !== undefined
713+ ) {
714+ await this . queryServer . trimCacheInDatabase (
715+ this . databaseManager . currentDatabaseItem ,
716+ token ,
717+ ) ;
718+ }
719+ } ,
720+ {
721+ title : "Trimming cache" ,
722+ } ,
723+ ) ;
724+ }
725+
706726 private async handleGetCurrentDatabase ( ) : Promise < string | undefined > {
707727 const dbItem = await this . getDatabaseItemInternal ( undefined ) ;
708728 return dbItem ?. databaseUri . fsPath ;
Original file line number Diff line number Diff line change 1+ import { trimCache } from "./../new-messages" ;
12import { CancellationToken } from "vscode" ;
23import { CodeQLCliServer } from "../../codeql-cli/cli" ;
34import { ProgressCallback } from "../../common/vscode/progress" ;
@@ -17,6 +18,7 @@ import { QueryOutputDir } from "../../run-queries-shared";
1718import { QueryServerClient } from "./query-server-client" ;
1819import {
1920 clearCacheInDatabase ,
21+ trimCacheInDatabase ,
2022 compileAndRunQueryAgainstDatabaseCore ,
2123} from "./run-queries" ;
2224import { upgradeDatabaseExplicit } from "./upgrades" ;
@@ -53,13 +55,21 @@ export class LegacyQueryRunner extends QueryRunner {
5355 ) {
5456 this . qs . onDidStartQueryServer ( callBack ) ;
5557 }
58+
5659 async clearCacheInDatabase (
5760 dbItem : DatabaseItem ,
5861 token : CancellationToken ,
5962 ) : Promise < void > {
6063 await clearCacheInDatabase ( this . qs , dbItem , token ) ;
6164 }
6265
66+ async trimCacheInDatabase (
67+ dbItem : DatabaseItem ,
68+ token : CancellationToken ,
69+ ) : Promise < void > {
70+ await trimCacheInDatabase ( this . qs , dbItem , token ) ;
71+ }
72+
6373 public async compileAndRunQueryAgainstDatabaseCore (
6474 dbPath : string ,
6575 query : CoreQueryTarget ,
Original file line number Diff line number Diff line change @@ -214,6 +214,27 @@ export async function clearCacheInDatabase(
214214 return qs . sendRequest ( messages . clearCache , params , token ) ;
215215}
216216
217+ export async function trimCacheInDatabase (
218+ qs : qsClient . QueryServerClient ,
219+ dbItem : DatabaseItem ,
220+ token : CancellationToken ,
221+ ) : Promise < messages . ClearCacheResult > {
222+ if ( dbItem . contents === undefined ) {
223+ throw new Error ( "Can't clear the cache in an invalid database." ) ;
224+ }
225+
226+ const db : messages . Dataset = {
227+ dbDir : dbItem . contents . datasetUri . fsPath ,
228+ workingSet : "default" ,
229+ } ;
230+
231+ const params : messages . TrimCacheParams = {
232+ db,
233+ } ;
234+
235+ return qs . sendRequest ( messages . trimCache , params , token ) ;
236+ }
237+
217238function reportNoUpgradePath (
218239 qlProgram : messages . QlProgram ,
219240 queryDbscheme : string ,
Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ import {
1010 clearPackCache ,
1111 deregisterDatabases ,
1212 registerDatabases ,
13+ trimCache ,
14+ TrimCacheParams ,
1315 upgradeDatabase ,
1416} from "./new-messages" ;
1517import { CoreQueryResults , CoreQueryTarget , QueryRunner } from "./query-runner" ;
@@ -70,6 +72,21 @@ export class NewQueryRunner extends QueryRunner {
7072 await this . qs . sendRequest ( clearCache , params , token ) ;
7173 }
7274
75+ async trimCacheInDatabase (
76+ dbItem : DatabaseItem ,
77+ token : CancellationToken ,
78+ ) : Promise < void > {
79+ if ( dbItem . contents === undefined ) {
80+ throw new Error ( "Can't trim the cache in an invalid database." ) ;
81+ }
82+
83+ const db = dbItem . databaseUri . fsPath ;
84+ const params : TrimCacheParams = {
85+ db,
86+ } ;
87+ await this . qs . sendRequest ( trimCache , params , token ) ;
88+ }
89+
7390 public async compileAndRunQueryAgainstDatabaseCore (
7491 dbPath : string ,
7592 query : CoreQueryTarget ,
Original file line number Diff line number Diff line change @@ -67,6 +67,11 @@ export abstract class QueryRunner {
6767 token : CancellationToken ,
6868 ) : Promise < void > ;
6969
70+ abstract trimCacheInDatabase (
71+ dbItem : DatabaseItem ,
72+ token : CancellationToken ,
73+ ) : Promise < void > ;
74+
7075 /**
7176 * Overridden in subclasses to evaluate the query via the query server and return the results.
7277 */
You can’t perform that action at this time.
0 commit comments