Skip to content

Commit 7217a7a

Browse files
author
Benjamin Pasero
committed
storage - disable global storage using sqlite for now
1 parent b5b15c1 commit 7217a7a

7 files changed

Lines changed: 86 additions & 22 deletions

File tree

src/vs/base/node/storage.ts

Lines changed: 75 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { Database, Statement } from 'vscode-sqlite3';
7-
import { Disposable } from 'vs/base/common/lifecycle';
7+
import { Disposable, IDisposable } from 'vs/base/common/lifecycle';
88
import { Emitter, Event } from 'vs/base/common/event';
99
import { RunOnceScheduler } from 'vs/base/common/async';
1010
import { isUndefinedOrNull } from 'vs/base/common/types';
@@ -33,7 +33,32 @@ enum StorageState {
3333
Closed
3434
}
3535

36-
export class Storage extends Disposable {
36+
export interface IStorage extends IDisposable {
37+
38+
readonly size: number;
39+
readonly onDidChangeStorage: Event<string>;
40+
41+
init(): Promise<void>;
42+
43+
get(key: string, fallbackValue: string): string;
44+
get(key: string, fallbackValue?: string): string | undefined;
45+
46+
getBoolean(key: string, fallbackValue: boolean): boolean;
47+
getBoolean(key: string, fallbackValue?: boolean): boolean | undefined;
48+
49+
getInteger(key: string, fallbackValue: number): number;
50+
getInteger(key: string, fallbackValue?: number): number | undefined;
51+
52+
set(key: string, value: any): Promise<void>;
53+
delete(key: string): Promise<void>;
54+
55+
close(): Promise<void>;
56+
57+
getItems(): Promise<Map<string, string>>;
58+
checkIntegrity(full: boolean): Promise<string>;
59+
}
60+
61+
export class Storage extends Disposable implements IStorage {
3762
_serviceBrand: any;
3863

3964
private static readonly FLUSH_DELAY = 100;
@@ -509,4 +534,52 @@ class SQLiteStorageLogger {
509534
this.options!.errorLogger!(error);
510535
}
511536
}
537+
}
538+
539+
export class NullStorage extends Disposable implements IStorage {
540+
541+
readonly size = 0;
542+
readonly onDidChangeStorage = Event.None;
543+
544+
private items = new Map<string, string>();
545+
546+
init(): Promise<void> { return Promise.resolve(); }
547+
548+
get(key: string, fallbackValue: string): string;
549+
get(key: string, fallbackValue?: string): string | undefined;
550+
get(key: string, fallbackValue?: string): string | undefined {
551+
return void 0;
552+
}
553+
554+
getBoolean(key: string, fallbackValue: boolean): boolean;
555+
getBoolean(key: string, fallbackValue?: boolean): boolean | undefined;
556+
getBoolean(key: string, fallbackValue?: boolean): boolean | undefined {
557+
return void 0;
558+
}
559+
560+
getInteger(key: string, fallbackValue: number): number;
561+
getInteger(key: string, fallbackValue?: number): number | undefined;
562+
getInteger(key: string, fallbackValue?: number): number | undefined {
563+
return void 0;
564+
}
565+
566+
set(key: string, value: any): Promise<void> {
567+
return Promise.resolve();
568+
}
569+
570+
delete(key: string): Promise<void> {
571+
return Promise.resolve();
572+
}
573+
574+
close(): Promise<void> {
575+
return Promise.resolve();
576+
}
577+
578+
getItems(): Promise<Map<string, string>> {
579+
return Promise.resolve(this.items);
580+
}
581+
582+
checkIntegrity(full: boolean): Promise<string> {
583+
return Promise.resolve('ok');
584+
}
512585
}

src/vs/platform/storage/node/storageService.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { Event, Emitter } from 'vs/base/common/event';
88
import { ILogService } from 'vs/platform/log/common/log';
99
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
1010
import { IWorkspaceStorageChangeEvent, IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
11-
import { Storage, IStorageLoggingOptions } from 'vs/base/node/storage';
11+
import { Storage, IStorageLoggingOptions, NullStorage, IStorage } from 'vs/base/node/storage';
1212
import { IStorageLegacyService, StorageLegacyScope } from 'vs/platform/storage/common/storageLegacyService';
1313
import { startsWith } from 'vs/base/common/strings';
1414
import { Action } from 'vs/base/common/actions';
@@ -29,7 +29,6 @@ export class StorageService extends Disposable implements IStorageService {
2929
private _onWillSaveState: Emitter<void> = this._register(new Emitter<void>());
3030
get onWillSaveState(): Event<void> { return this._onWillSaveState.event; }
3131

32-
3332
private _hasErrors = false;
3433
get hasErrors(): boolean { return this._hasErrors; }
3534

@@ -51,17 +50,18 @@ export class StorageService extends Disposable implements IStorageService {
5150
return this._onStorageError.event;
5251
}
5352

54-
private globalStorage: Storage;
53+
private globalStorage: IStorage;
5554
private globalStorageWorkspacePath: string;
5655

5756
private workspaceStoragePath: string;
58-
private workspaceStorage: Storage;
57+
private workspaceStorage: IStorage;
5958
private workspaceStorageListener: IDisposable;
6059

6160
private loggingOptions: IStorageLoggingOptions;
6261

6362
constructor(
6463
workspaceStoragePath: string,
64+
disableGlobalStorage: boolean,
6565
@ILogService logService: ILogService,
6666
@IEnvironmentService environmentService: IEnvironmentService
6767
) {
@@ -84,7 +84,7 @@ export class StorageService extends Disposable implements IStorageService {
8484
};
8585

8686
this.globalStorageWorkspacePath = workspaceStoragePath === StorageService.IN_MEMORY_PATH ? StorageService.IN_MEMORY_PATH : StorageService.IN_MEMORY_PATH;
87-
this.globalStorage = new Storage({ path: this.globalStorageWorkspacePath, logging: this.loggingOptions });
87+
this.globalStorage = disableGlobalStorage ? new NullStorage() : new Storage({ path: this.globalStorageWorkspacePath, logging: this.loggingOptions });
8888
this._register(this.globalStorage.onDidChangeStorage(key => this.handleDidChangeStorage(key, StorageScope.GLOBAL)));
8989

9090
this.createWorkspaceStorage(workspaceStoragePath);
@@ -156,7 +156,7 @@ export class StorageService extends Disposable implements IStorageService {
156156
]).then(() => void 0);
157157
}
158158

159-
private getStorage(scope: StorageScope): Storage {
159+
private getStorage(scope: StorageScope): IStorage {
160160
return scope === StorageScope.GLOBAL ? this.globalStorage : this.workspaceStorage;
161161
}
162162

src/vs/platform/storage/test/node/storageService.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ suite('StorageService', () => {
8484
const storageDir = uniqueStorageDir();
8585
await mkdirp(storageDir);
8686

87-
const storage = new StorageService(join(storageDir, 'storage.db'), new NullLogService(), TestEnvironmentService);
87+
const storage = new StorageService(join(storageDir, 'storage.db'), false, new NullLogService(), TestEnvironmentService);
8888
await storage.init();
8989

9090
storage.store('bar', 'foo', StorageScope.WORKSPACE);

src/vs/platform/telemetry/test/electron-browser/commonProperties.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ suite('Telemetry - common properties', function () {
2424
let nestStorage2Service: IStorageService;
2525

2626
setup(() => {
27-
nestStorage2Service = new StorageService(':memory:', new NullLogService(), TestEnvironmentService);
27+
nestStorage2Service = new StorageService(':memory:', false, new NullLogService(), TestEnvironmentService);
2828
});
2929

3030
teardown(done => {

src/vs/workbench/electron-browser/main.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ function createStorageService(workspaceStorageFolder: string, payload: IWorkspac
284284
// Return early if we are using in-memory storage
285285
const useInMemoryStorage = !!environmentService.extensionTestsPath; /* never keep any state when running extension tests */
286286
if (useInMemoryStorage) {
287-
const storageService = new StorageService(StorageService.IN_MEMORY_PATH, logService, environmentService);
287+
const storageService = new StorageService(StorageService.IN_MEMORY_PATH, true, logService, environmentService);
288288

289289
return storageService.init().then(() => storageService);
290290
}
@@ -296,7 +296,7 @@ function createStorageService(workspaceStorageFolder: string, payload: IWorkspac
296296
return exists(workspaceStorageDBPath).then(exists => {
297297
perf.mark('didCheckWorkspaceStorageExists');
298298

299-
const storageService = new StorageService(workspaceStorageDBPath, logService, environmentService);
299+
const storageService = new StorageService(workspaceStorageDBPath, true, logService, environmentService);
300300

301301
return storageService.init().then(() => {
302302
if (exists) {

src/vs/workbench/electron-browser/shell.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,6 @@ export class WorkbenchShell extends Disposable {
285285
}
286286

287287
private logStorageTelemetry(): void {
288-
const globalStorageInitDuration = perf.getDuration('willInitGlobalStorage', 'didInitGlobalStorage');
289288
const workspaceStorageRequireDuration = perf.getDuration('willRequireSQLite', 'didRequireSQLite');
290289
const workspaceStorageInitDuration = perf.getDuration('willInitWorkspaceStorage', 'didInitWorkspaceStorage');
291290
const workspaceStorageFileExistsDuration = perf.getDuration('willCheckWorkspaceStorageExists', 'didCheckWorkspaceStorageExists');
@@ -305,29 +304,25 @@ export class WorkbenchShell extends Disposable {
305304

306305
/* __GDPR__
307306
"sqliteStorageError3" : {
308-
"globalReadTime" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true },
309307
"workspaceExistsTime" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true },
310308
"workspaceRequireTime" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true },
311309
"workspaceReadTime" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true },
312310
"workspaceMigrationTime" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true },
313311
"localStorageTime" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true },
314312
"workbenchRequireTime" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true },
315-
"globalKeys" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true },
316313
"workspaceKeys" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true },
317314
"startupKind": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true },
318315
"integrityWorkspace" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true },
319316
"storageError": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true }
320317
}
321318
*/
322319
this.telemetryService.publicLog('sqliteStorageError3', {
323-
'globalReadTime': globalStorageInitDuration,
324320
'workspaceExistsTime': workspaceStorageFileExistsDuration,
325321
'workspaceMigrationTime': workspaceStorageMigrationDuration,
326322
'workspaceRequireTime': workspaceStorageRequireDuration,
327323
'workspaceReadTime': workspaceStorageInitDuration,
328324
'localStorageTime': localStorageDuration,
329325
'workbenchRequireTime': workbenchLoadDuration,
330-
'globalKeys': this.storageService.storage.getSize(StorageScope.GLOBAL),
331326
'workspaceKeys': this.storageService.storage.getSize(StorageScope.WORKSPACE),
332327
'startupKind': this.lifecycleService.startupKind,
333328
'integrityWorkspace': workspaceIntegrity,
@@ -354,7 +349,6 @@ export class WorkbenchShell extends Disposable {
354349

355350
/* __GDPR__
356351
"sqliteStorageTimers3" : {
357-
"globalReadTime" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true },
358352
"workspaceExistsTime" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true },
359353
"workspaceMigrationTime" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true },
360354
"workspaceRequireTime" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true },
@@ -363,13 +357,11 @@ export class WorkbenchShell extends Disposable {
363357
"integrityWorkspace" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true },
364358
"workspaceIntegrityCheckTime" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true },
365359
"workbenchRequireTime" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true },
366-
"globalKeys" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true },
367360
"workspaceKeys" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true },
368361
"startupKind": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true }
369362
}
370363
*/
371364
this.telemetryService.publicLog('sqliteStorageTimers3', {
372-
'globalReadTime': globalStorageInitDuration,
373365
'workspaceExistsTime': workspaceStorageFileExistsDuration,
374366
'workspaceMigrationTime': workspaceStorageMigrationDuration,
375367
'workspaceRequireTime': workspaceStorageRequireDuration,
@@ -378,7 +370,6 @@ export class WorkbenchShell extends Disposable {
378370
'integrityWorkspace': workspaceIntegrity,
379371
'workspaceIntegrityCheckTime': perf.getDuration('willCheckWorkspaceStorageIntegrity', 'didCheckWorkspaceStorageIntegrity'),
380372
'workbenchRequireTime': workbenchLoadDuration,
381-
'globalKeys': this.storageService.storage.getSize(StorageScope.GLOBAL),
382373
'workspaceKeys': this.storageService.storage.getSize(StorageScope.WORKSPACE),
383374
'startupKind': this.lifecycleService.startupKind
384375
});

src/vs/workbench/test/workbenchTestServices.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ export class TestPartService implements IPartService {
531531
export class TestStorageService extends StorageService {
532532

533533
constructor() {
534-
super(':memory:', new NullLogService(), TestEnvironmentService);
534+
super(':memory:', false, new NullLogService(), TestEnvironmentService);
535535
}
536536
}
537537

0 commit comments

Comments
 (0)