Skip to content

Commit 6e33b3c

Browse files
committed
Fix bug where dbs are lost on restart
If the workspace is restarted while databases are being loaded, this change prevents any from being lost. The bug was that each time a database was added when rehydrating a db from persisted state on startup, the persisted db list was being updated. Instead of updating the list each time we add a db, on restart, instead update the persisted list only after all are added. Note that we need to update the persisted list after reading it in since the act of rehydrating a database _may_ change its persisted state. For example, the primary language of the database may be initialized if it was not able to be determined originally.
2 parents 9957b21 + 94ef752 commit 6e33b3c

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

extensions/ql-vscode/src/databases.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,9 @@ export class DatabaseManager extends DisposableObject {
684684
this._onDidChangeDatabaseItem.fire(event);
685685
});
686686

687-
await this.addDatabaseItem(progress, token, item);
687+
// Avoid persisting the database state after adding since that should happen only after
688+
// all databases have been added.
689+
await this.addDatabaseItem(progress, token, item, false);
688690
return item;
689691
}
690692

@@ -724,6 +726,7 @@ export class DatabaseManager extends DisposableObject {
724726
void this.logger.log(`Error loading database ${database.uri}: ${e}.`);
725727
}
726728
}
729+
await this.updatePersistedDatabaseList();
727730
} catch (e) {
728731
// database list had an unexpected type - nothing to be done?
729732
void showAndLogErrorMessage(`Database list loading failed: ${getErrorMessage(e)}`);
@@ -784,10 +787,14 @@ export class DatabaseManager extends DisposableObject {
784787
private async addDatabaseItem(
785788
progress: ProgressCallback,
786789
token: vscode.CancellationToken,
787-
item: DatabaseItem
790+
item: DatabaseItem,
791+
updatePersistedState = true
788792
) {
789793
this._databaseItems.push(item);
790-
await this.updatePersistedDatabaseList();
794+
795+
if (updatePersistedState) {
796+
await this.updatePersistedDatabaseList();
797+
}
791798

792799
// Add this database item to the allow-list
793800
// Database items reconstituted from persisted state

extensions/ql-vscode/src/legacy-query-server/run-queries.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export class QueryInProgress {
5454
}
5555

5656
get compiledQueryPath() {
57-
return path.join(this.querySaveDir, 'compiledQuery.qlo');
57+
return this.queryEvalInfo.compileQueryPath;
5858
}
5959

6060

extensions/ql-vscode/src/run-queries-shared.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ export class QueryEvaluationInfo {
192192
if (await this.hasDil()) {
193193
return this.dilPath;
194194
}
195-
const compiledQuery = path.join(this.querySaveDir, 'compiledQuery.qlo');
195+
const compiledQuery = this.compileQueryPath;
196196
if (!(await fs.pathExists(compiledQuery))) {
197197
if (await cliServer.cliConstraints.supportsNewQueryServer()) {
198198
// This could be from the new query server

0 commit comments

Comments
 (0)