Re-use existing database if one for the same language is already downloaded
We'd like to select an existing database for our query, if on is already downloaded and matches the query language. Previously we were re-using the database if the language and name matched (e.g. the name would be `github/codeql`).
This commit is contained in:
@@ -911,6 +911,17 @@ export class DatabaseManager extends DisposableObject {
|
||||
return dbs[0];
|
||||
}
|
||||
|
||||
public async digForDatabaseWithSameLanguage(
|
||||
language: string,
|
||||
): Promise<DatabaseItem | undefined> {
|
||||
const dbItems = this.databaseItems || [];
|
||||
const dbs = dbItems.filter((db) => db.language === language);
|
||||
if (dbs.length === 0) {
|
||||
return undefined;
|
||||
}
|
||||
return dbs[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the index of the workspace folder that corresponds to the source archive of `item`
|
||||
* if there is one, and -1 otherwise.
|
||||
|
||||
@@ -231,17 +231,30 @@ export class SkeletonQueryWizard {
|
||||
|
||||
const databaseNwo = QUERY_LANGUAGE_TO_DATABASE_REPO[this.language];
|
||||
|
||||
const databaseItem = await this.databaseManager.digForDatabaseItem(
|
||||
// Check that we haven't already downloaded a database for this language
|
||||
const existingDatabaseItem = await this.databaseManager.digForDatabaseItem(
|
||||
this.language,
|
||||
databaseNwo,
|
||||
);
|
||||
|
||||
if (databaseItem) {
|
||||
if (existingDatabaseItem) {
|
||||
// select the found database
|
||||
await this.databaseManager.setCurrentDatabaseItem(databaseItem);
|
||||
await this.databaseManager.setCurrentDatabaseItem(existingDatabaseItem);
|
||||
} else {
|
||||
// download new database and select it
|
||||
await this.downloadDatabase();
|
||||
const sameLanguageDatabaseItem =
|
||||
await this.databaseManager.digForDatabaseWithSameLanguage(
|
||||
this.language,
|
||||
);
|
||||
|
||||
if (sameLanguageDatabaseItem) {
|
||||
// select the found database
|
||||
await this.databaseManager.setCurrentDatabaseItem(
|
||||
sameLanguageDatabaseItem,
|
||||
);
|
||||
} else {
|
||||
// download new database and select it
|
||||
await this.downloadDatabase();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ describe("SkeletonQueryWizard", () => {
|
||||
const mockDatabaseManager = mockedObject<DatabaseManager>({
|
||||
setCurrentDatabaseItem: jest.fn(),
|
||||
digForDatabaseItem: jest.fn(),
|
||||
digForDatabaseWithSameLanguage: jest.fn(),
|
||||
});
|
||||
const mockCli = mockedObject<CodeQLCliServer>({
|
||||
resolveLanguages: jest
|
||||
|
||||
Reference in New Issue
Block a user