Skip to content

Commit 3efd421

Browse files
authored
Settings Sync reset the profile state after updating VS Code (microsoft#166101) (microsoft#167298)
1 parent 226eb40 commit 3efd421

File tree

4 files changed

+31
-13
lines changed

4 files changed

+31
-13
lines changed

src/vs/base/parts/storage/common/storage.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ export enum StorageHint {
1414
// does not exist on disk yet. This allows
1515
// the storage library to improve startup
1616
// time by not checking the storage for data.
17-
STORAGE_DOES_NOT_EXIST
17+
STORAGE_DOES_NOT_EXIST,
18+
19+
// A hint to the storage that the storage
20+
// is backed by an in-memory storage.
21+
STORAGE_IN_MEMORY
1822
}
1923

2024
export interface IStorageOptions {
@@ -339,6 +343,10 @@ export class Storage extends Disposable implements IStorage {
339343
return new Promise(resolve => this.whenFlushedCallbacks.push(resolve));
340344
}
341345

346+
isInMemory(): boolean {
347+
return this.options.hint === StorageHint.STORAGE_IN_MEMORY;
348+
}
349+
342350
override dispose(): void {
343351
this.flushDelayer.dispose();
344352

src/vs/platform/storage/common/storage.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { Emitter, Event, PauseableEmitter } from 'vs/base/common/event';
88
import { Disposable, dispose, MutableDisposable } from 'vs/base/common/lifecycle';
99
import { mark } from 'vs/base/common/performance';
1010
import { isUndefinedOrNull } from 'vs/base/common/types';
11-
import { InMemoryStorageDatabase, IStorage, Storage } from 'vs/base/parts/storage/common/storage';
11+
import { InMemoryStorageDatabase, IStorage, Storage, StorageHint } from 'vs/base/parts/storage/common/storage';
1212
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
1313
import { isUserDataProfile, IUserDataProfile } from 'vs/platform/userDataProfile/common/userDataProfile';
1414
import { IAnyWorkspaceIdentifier } from 'vs/platform/workspace/common/workspace';
@@ -623,9 +623,9 @@ export function isProfileUsingDefaultStorage(profile: IUserDataProfile): boolean
623623

624624
export class InMemoryStorageService extends AbstractStorageService {
625625

626-
private readonly applicationStorage = this._register(new Storage(new InMemoryStorageDatabase()));
627-
private readonly profileStorage = this._register(new Storage(new InMemoryStorageDatabase()));
628-
private readonly workspaceStorage = this._register(new Storage(new InMemoryStorageDatabase()));
626+
private readonly applicationStorage = this._register(new Storage(new InMemoryStorageDatabase(), { hint: StorageHint.STORAGE_IN_MEMORY }));
627+
private readonly profileStorage = this._register(new Storage(new InMemoryStorageDatabase(), { hint: StorageHint.STORAGE_IN_MEMORY }));
628+
private readonly workspaceStorage = this._register(new Storage(new InMemoryStorageDatabase(), { hint: StorageHint.STORAGE_IN_MEMORY }));
629629

630630
constructor() {
631631
super();

src/vs/platform/storage/electron-main/storageMain.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ export interface IStorageMain extends IDisposable {
9191
*/
9292
delete(key: string): void;
9393

94+
/**
95+
* Whether the storage is using in-memory persistence or not.
96+
*/
97+
isInMemory(): boolean;
98+
9499
/**
95100
* Close the storage connection.
96101
*/
@@ -111,7 +116,7 @@ abstract class BaseStorageMain extends Disposable implements IStorageMain {
111116
private readonly _onDidCloseStorage = this._register(new Emitter<void>());
112117
readonly onDidCloseStorage = this._onDidCloseStorage.event;
113118

114-
private _storage: IStorage = new Storage(new InMemoryStorageDatabase()); // storage is in-memory until initialized
119+
private _storage = new Storage(new InMemoryStorageDatabase(), { hint: StorageHint.STORAGE_IN_MEMORY }); // storage is in-memory until initialized
115120
get storage(): IStorage { return this._storage; }
116121

117122
abstract get path(): string | undefined;
@@ -130,6 +135,10 @@ abstract class BaseStorageMain extends Disposable implements IStorageMain {
130135
super();
131136
}
132137

138+
isInMemory(): boolean {
139+
return this._storage.isInMemory();
140+
}
141+
133142
init(): Promise<void> {
134143
if (!this.initializePromise) {
135144
this.initializePromise = (async () => {
@@ -188,7 +197,7 @@ abstract class BaseStorageMain extends Disposable implements IStorageMain {
188197
return storage.init();
189198
}
190199

191-
protected abstract doCreate(): Promise<IStorage>;
200+
protected abstract doCreate(): Promise<Storage>;
192201

193202
get items(): Map<string, string> { return this._storage.items; }
194203

@@ -281,10 +290,10 @@ class BaseProfileAwareStorageMain extends BaseStorageMain {
281290
super(logService, fileService);
282291
}
283292

284-
protected async doCreate(): Promise<IStorage> {
293+
protected async doCreate(): Promise<Storage> {
285294
return new Storage(new SQLiteStorageDatabase(this.path ?? SQLiteStorageDatabase.IN_MEMORY_PATH, {
286295
logging: this.createLoggingOptions()
287-
}));
296+
}), !this.path ? { hint: StorageHint.STORAGE_IN_MEMORY } : undefined);
288297
}
289298
}
290299

@@ -359,12 +368,12 @@ export class WorkspaceStorageMain extends BaseStorageMain {
359368
super(logService, fileService);
360369
}
361370

362-
protected async doCreate(): Promise<IStorage> {
371+
protected async doCreate(): Promise<Storage> {
363372
const { storageFilePath, wasCreated } = await this.prepareWorkspaceStorageFolder();
364373

365374
return new Storage(new SQLiteStorageDatabase(storageFilePath, {
366375
logging: this.createLoggingOptions()
367-
}), { hint: wasCreated ? StorageHint.STORAGE_DOES_NOT_EXIST : undefined });
376+
}), { hint: this.options.useInMemoryStorage ? StorageHint.STORAGE_IN_MEMORY : wasCreated ? StorageHint.STORAGE_DOES_NOT_EXIST : undefined });
368377
}
369378

370379
private async prepareWorkspaceStorageFolder(): Promise<{ storageFilePath: string; wasCreated: boolean }> {
@@ -420,7 +429,7 @@ export class InMemoryStorageMain extends BaseStorageMain {
420429
return undefined; // in-memory has no path
421430
}
422431

423-
protected async doCreate(): Promise<IStorage> {
424-
return new Storage(new InMemoryStorageDatabase());
432+
protected async doCreate(): Promise<Storage> {
433+
return new Storage(new InMemoryStorageDatabase(), { hint: StorageHint.STORAGE_IN_MEMORY });
425434
}
426435
}

src/vs/platform/storage/test/electron-main/storageMainService.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ suite('StorageMainService', function () {
5454
}
5555

5656
async function testStorage(storage: IStorageMain, scope: StorageScope): Promise<void> {
57+
strictEqual(storage.isInMemory(), true);
5758

5859
// Telemetry: added after init unless workspace/profile scoped
5960
if (scope === StorageScope.APPLICATION) {

0 commit comments

Comments
 (0)