mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-14 01:25:37 -05:00
add migration state management improvement (#17799)
* add migration state management improvement * remove extra lines
This commit is contained in:
@@ -20,12 +20,14 @@ export class MigrationLocalStorage {
|
||||
const result: MigrationContext[] = [];
|
||||
const validMigrations: MigrationContext[] = [];
|
||||
|
||||
// fetch saved migrations
|
||||
const migrationMementos: MigrationContext[] = this.context.globalState.get(this.mementoToken) || [];
|
||||
for (let i = 0; i < migrationMementos.length; i++) {
|
||||
const migration = migrationMementos[i];
|
||||
migration.migrationContext = this.removeMigrationSecrets(migration.migrationContext);
|
||||
migration.sessionId = migration.sessionId ?? undefinedSessionId;
|
||||
if (migration.sourceConnectionProfile.serverName === connectionProfile.serverName) {
|
||||
// refresh migration status
|
||||
if (refreshStatus) {
|
||||
try {
|
||||
await this.refreshMigrationAzureAccount(migration);
|
||||
@@ -59,7 +61,25 @@ export class MigrationLocalStorage {
|
||||
}
|
||||
validMigrations.push(migration);
|
||||
}
|
||||
await this.context.globalState.update(this.mementoToken, validMigrations);
|
||||
|
||||
// only save updated migration context
|
||||
if (refreshStatus) {
|
||||
const migrations: MigrationContext[] = this.context.globalState.get(this.mementoToken) || [];
|
||||
validMigrations.forEach(migration => {
|
||||
const idx = migrations.findIndex(m => m.migrationContext.id === migration.migrationContext.id);
|
||||
if (idx > -1) {
|
||||
migrations[idx] = migration;
|
||||
}
|
||||
});
|
||||
|
||||
// check global state for migrations count mismatch, avoid saving
|
||||
// state if the count has changed when a migration may have been added
|
||||
const current: MigrationContext[] = this.context.globalState.get(this.mementoToken) || [];
|
||||
if (current.length === migrations.length) {
|
||||
await this.context.globalState.update(this.mementoToken, migrations);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user