Skip to content

Commit fbdb6f5

Browse files
author
Benjamin Pasero
committed
sqlite - more next storage service adoption
1 parent 113459a commit fbdb6f5

33 files changed

Lines changed: 256 additions & 296 deletions

File tree

src/vs/base/common/async.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ export class SimpleThrottler {
172172
* delayer.trigger(() => { return makeTheTrip(); });
173173
* }
174174
*/
175-
export class Delayer<T> {
175+
export class Delayer<T> implements IDisposable {
176176

177177
private timeout: any;
178178
private completionPromise: TPromise | null;
@@ -232,6 +232,10 @@ export class Delayer<T> {
232232
this.timeout = null;
233233
}
234234
}
235+
236+
dispose(): void {
237+
this.cancelTimeout();
238+
}
235239
}
236240

237241
/**

src/vs/platform/extensionManagement/common/extensionEnablementService.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { IDisposable, dispose } from 'vs/base/common/lifecycle';
99
import { IExtensionManagementService, DidUninstallExtensionEvent, IExtensionEnablementService, IExtensionIdentifier, EnablementState, ILocalExtension, isIExtensionIdentifier, LocalExtensionType } from 'vs/platform/extensionManagement/common/extensionManagement';
1010
import { getIdFromLocalExtensionId, areSameExtensions } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
1111
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
12-
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
12+
import { INextStorage2Service, StorageScope } from 'vs/platform/storage2/common/storage2';
1313
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
1414

1515
const DISABLED_EXTENSIONS_STORAGE_PATH = 'extensionsIdentifiers/disabled';
@@ -25,7 +25,7 @@ export class ExtensionEnablementService implements IExtensionEnablementService {
2525
public readonly onEnablementChanged: Event<IExtensionIdentifier> = this._onEnablementChanged.event;
2626

2727
constructor(
28-
@IStorageService private storageService: IStorageService,
28+
@INextStorage2Service private nextStorage2Service: INextStorage2Service,
2929
@IWorkspaceContextService private contextService: IWorkspaceContextService,
3030
@IEnvironmentService private environmentService: IEnvironmentService,
3131
@IExtensionManagementService private extensionManagementService: IExtensionManagementService
@@ -275,15 +275,15 @@ export class ExtensionEnablementService implements IExtensionEnablementService {
275275
if (scope === StorageScope.WORKSPACE && !this.hasWorkspace) {
276276
return [];
277277
}
278-
const value = this.storageService.get(storageId, scope, '');
278+
const value = this.nextStorage2Service.get(storageId, scope, '');
279279
return value ? JSON.parse(value) : [];
280280
}
281281

282282
private _setExtensions(storageId: string, extensions: IExtensionIdentifier[], scope: StorageScope, extension: IExtensionIdentifier): void {
283283
if (extensions.length) {
284-
this.storageService.store(storageId, JSON.stringify(extensions.map(({ id, uuid }) => (<IExtensionIdentifier>{ id, uuid }))), scope);
284+
this.nextStorage2Service.set(storageId, JSON.stringify(extensions.map(({ id, uuid }) => (<IExtensionIdentifier>{ id, uuid }))), scope);
285285
} else {
286-
this.storageService.remove(storageId, scope);
286+
this.nextStorage2Service.delete(storageId, scope);
287287
}
288288
}
289289

src/vs/platform/extensionManagement/test/common/extensionEnablementService.test.ts renamed to src/vs/platform/extensionManagement/test/electron-browser/extensionEnablementService.test.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,28 @@ import { IExtensionManagementService, IExtensionEnablementService, DidUninstallE
88
import { ExtensionEnablementService } from 'vs/platform/extensionManagement/common/extensionEnablementService';
99
import { TestInstantiationService } from 'vs/platform/instantiation/test/common/instantiationServiceMock';
1010
import { Emitter } from 'vs/base/common/event';
11-
import { StorageService, InMemoryLocalStorage } from 'vs/platform/storage/common/storageService';
12-
import { IStorageService } from 'vs/platform/storage/common/storage';
1311
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
1412
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
13+
import { INextStorage2Service } from 'vs/platform/storage2/common/storage2';
14+
import { TestNextStorage2Service } from 'vs/workbench/test/workbenchTestServices';
1515

16-
function storageService(instantiationService: TestInstantiationService): IStorageService {
17-
let service = instantiationService.get(IStorageService);
16+
function nextStorage2Service(instantiationService: TestInstantiationService): INextStorage2Service {
17+
let service = instantiationService.get(INextStorage2Service);
1818
if (!service) {
1919
let workspaceContextService = instantiationService.get(IWorkspaceContextService);
2020
if (!workspaceContextService) {
2121
workspaceContextService = instantiationService.stub(IWorkspaceContextService, <IWorkspaceContextService>{
2222
getWorkbenchState: () => WorkbenchState.FOLDER,
2323
});
2424
}
25-
service = instantiationService.stub(IStorageService, instantiationService.createInstance(StorageService, new InMemoryLocalStorage(), new InMemoryLocalStorage()));
25+
service = instantiationService.stub(INextStorage2Service, new TestNextStorage2Service());
2626
}
2727
return service;
2828
}
2929

30-
3130
export class TestExtensionEnablementService extends ExtensionEnablementService {
3231
constructor(instantiationService: TestInstantiationService) {
33-
super(storageService(instantiationService), instantiationService.get(IWorkspaceContextService),
32+
super(nextStorage2Service(instantiationService), instantiationService.get(IWorkspaceContextService),
3433
instantiationService.get(IEnvironmentService) || instantiationService.stub(IEnvironmentService, {} as IEnvironmentService),
3534
instantiationService.get(IExtensionManagementService) || instantiationService.stub(IExtensionManagementService,
3635
{ onDidUninstallExtension: new Emitter<DidUninstallExtensionEvent>().event } as IExtensionManagementService));

src/vs/platform/extensionManagement/test/common/extensionManagement.test.ts renamed to src/vs/platform/extensionManagement/test/electron-browser/extensionManagement.test.ts

File renamed without changes.

src/vs/platform/integrity/node/integrityServiceImpl.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { IIntegrityService, IntegrityTestResult, ChecksumPair } from 'vs/platfor
1010
import product from 'vs/platform/node/product';
1111
import { URI } from 'vs/base/common/uri';
1212
import Severity from 'vs/base/common/severity';
13-
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
13+
import { INextStorage2Service, StorageScope } from 'vs/platform/storage2/common/storage2';
1414
import { ILifecycleService, LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle';
1515
import { INotificationService } from 'vs/platform/notification/common/notification';
1616

@@ -22,16 +22,16 @@ interface IStorageData {
2222
class IntegrityStorage {
2323
private static readonly KEY = 'integrityService';
2424

25-
private _storageService: IStorageService;
25+
private _nextStorage2Service: INextStorage2Service;
2626
private _value: IStorageData;
2727

28-
constructor(storageService: IStorageService) {
29-
this._storageService = storageService;
28+
constructor(nextStorage2Service: INextStorage2Service) {
29+
this._nextStorage2Service = nextStorage2Service;
3030
this._value = this._read();
3131
}
3232

3333
private _read(): IStorageData {
34-
let jsonValue = this._storageService.get(IntegrityStorage.KEY, StorageScope.GLOBAL);
34+
let jsonValue = this._nextStorage2Service.get(IntegrityStorage.KEY, StorageScope.GLOBAL);
3535
if (!jsonValue) {
3636
return null;
3737
}
@@ -48,7 +48,7 @@ class IntegrityStorage {
4848

4949
public set(data: IStorageData): void {
5050
this._value = data;
51-
this._storageService.store(IntegrityStorage.KEY, JSON.stringify(this._value), StorageScope.GLOBAL);
51+
this._nextStorage2Service.set(IntegrityStorage.KEY, JSON.stringify(this._value), StorageScope.GLOBAL);
5252
}
5353
}
5454

@@ -61,10 +61,10 @@ export class IntegrityServiceImpl implements IIntegrityService {
6161

6262
constructor(
6363
@INotificationService private notificationService: INotificationService,
64-
@IStorageService storageService: IStorageService,
64+
@INextStorage2Service nextStorage2Service: INextStorage2Service,
6565
@ILifecycleService private lifecycleService: ILifecycleService
6666
) {
67-
this._storage = new IntegrityStorage(storageService);
67+
this._storage = new IntegrityStorage(nextStorage2Service);
6868

6969
this._isPurePromise = this._isPure();
7070

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

Lines changed: 0 additions & 97 deletions
This file was deleted.

src/vs/platform/storage2/electron-browser/nextStorage2Service.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -180,14 +180,4 @@ export class NextDelegatingStorage2Service extends Disposable implements INextSt
180180
private convertScope(scope: StorageScope): LocalStorageScope {
181181
return scope === StorageScope.GLOBAL ? LocalStorageScope.GLOBAL : LocalStorageScope.WORKSPACE;
182182
}
183-
}
184-
185-
export class NextInMemoryStorage2Service extends NextStorage2Service {
186-
187-
constructor(
188-
@ILogService logService: ILogService,
189-
@IEnvironmentService environmentService: IEnvironmentService
190-
) {
191-
super(':memory:', logService, environmentService);
192-
}
193183
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import * as assert from 'assert';
7+
import { StorageScope } from 'vs/platform/storage2/common/storage2';
8+
import { TestNextStorage2Service } from 'vs/workbench/test/workbenchTestServices';
9+
10+
suite('NextStorage2Service', () => {
11+
12+
test('Remove Data', () => {
13+
let storage = new TestNextStorage2Service();
14+
storage.set('Monaco.IDE.Core.Storage.Test.remove', 'foobar', StorageScope.GLOBAL);
15+
assert.strictEqual('foobar', storage.get('Monaco.IDE.Core.Storage.Test.remove', StorageScope.GLOBAL));
16+
17+
storage.delete('Monaco.IDE.Core.Storage.Test.remove', StorageScope.GLOBAL);
18+
assert.ok(!storage.get('Monaco.IDE.Core.Storage.Test.remove', StorageScope.GLOBAL));
19+
});
20+
21+
test('Get Data, Integer, Boolean', () => {
22+
let storage = new TestNextStorage2Service();
23+
24+
assert.strictEqual(storage.get('Monaco.IDE.Core.Storage.Test.get', StorageScope.GLOBAL, 'foobar'), 'foobar');
25+
assert.strictEqual(storage.get('Monaco.IDE.Core.Storage.Test.get', StorageScope.GLOBAL, ''), '');
26+
assert.strictEqual(storage.get('Monaco.IDE.Core.Storage.Test.getInteger', StorageScope.GLOBAL, 5), 5);
27+
assert.strictEqual(storage.get('Monaco.IDE.Core.Storage.Test.getInteger', StorageScope.GLOBAL, 0), 0);
28+
assert.strictEqual(storage.get('Monaco.IDE.Core.Storage.Test.getBoolean', StorageScope.GLOBAL, true), true);
29+
assert.strictEqual(storage.get('Monaco.IDE.Core.Storage.Test.getBoolean', StorageScope.GLOBAL, false), false);
30+
31+
storage.set('Monaco.IDE.Core.Storage.Test.get', 'foobar', StorageScope.GLOBAL);
32+
assert.strictEqual(storage.get('Monaco.IDE.Core.Storage.Test.get', StorageScope.GLOBAL), 'foobar');
33+
34+
storage.set('Monaco.IDE.Core.Storage.Test.get', '', StorageScope.GLOBAL);
35+
assert.strictEqual(storage.get('Monaco.IDE.Core.Storage.Test.get', StorageScope.GLOBAL), '');
36+
37+
storage.set('Monaco.IDE.Core.Storage.Test.getInteger', 5, StorageScope.GLOBAL);
38+
assert.strictEqual(storage.getInteger('Monaco.IDE.Core.Storage.Test.getInteger', StorageScope.GLOBAL), 5);
39+
40+
storage.set('Monaco.IDE.Core.Storage.Test.getInteger', 0, StorageScope.GLOBAL);
41+
assert.strictEqual(storage.getInteger('Monaco.IDE.Core.Storage.Test.getInteger', StorageScope.GLOBAL), 0);
42+
43+
storage.set('Monaco.IDE.Core.Storage.Test.getBoolean', true, StorageScope.GLOBAL);
44+
assert.strictEqual(storage.getBoolean('Monaco.IDE.Core.Storage.Test.getBoolean', StorageScope.GLOBAL), true);
45+
46+
storage.set('Monaco.IDE.Core.Storage.Test.getBoolean', false, StorageScope.GLOBAL);
47+
assert.strictEqual(storage.getBoolean('Monaco.IDE.Core.Storage.Test.getBoolean', StorageScope.GLOBAL), false);
48+
49+
assert.strictEqual(storage.get('Monaco.IDE.Core.Storage.Test.getDefault', StorageScope.GLOBAL, 'getDefault'), 'getDefault');
50+
assert.strictEqual(storage.getInteger('Monaco.IDE.Core.Storage.Test.getIntegerDefault', StorageScope.GLOBAL, 5), 5);
51+
assert.strictEqual(storage.getBoolean('Monaco.IDE.Core.Storage.Test.getBooleanDefault', StorageScope.GLOBAL, true), true);
52+
});
53+
});

src/vs/workbench/parts/codeEditor/electron-browser/largeFileOptimizations.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { IEditorContribution } from 'vs/editor/common/editorCommon';
1010
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
1111
import { registerEditorContribution } from 'vs/editor/browser/editorExtensions';
1212
import { INotificationService, Severity } from 'vs/platform/notification/common/notification';
13-
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
13+
import { INextStorage2Service, StorageScope } from 'vs/platform/storage2/common/storage2';
1414
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
1515

1616
/**
@@ -26,11 +26,11 @@ export class LargeFileOptimizationsWarner extends Disposable implements IEditorC
2626
private readonly _editor: ICodeEditor,
2727
@INotificationService private readonly _notificationService: INotificationService,
2828
@IConfigurationService private readonly _configurationService: IConfigurationService,
29-
@IStorageService private readonly _storageService: IStorageService,
29+
@INextStorage2Service private readonly _nextStorage2Service: INextStorage2Service,
3030
) {
3131
super();
3232

33-
this._isDisabled = this._storageService.getBoolean('editor.neverPromptForLargeFiles', StorageScope.GLOBAL, false);
33+
this._isDisabled = this._nextStorage2Service.getBoolean('editor.neverPromptForLargeFiles', StorageScope.GLOBAL, false);
3434

3535
this._register(this._editor.onDidChangeModel((e) => {
3636
const model = this._editor.getModel();
@@ -58,7 +58,7 @@ export class LargeFileOptimizationsWarner extends Disposable implements IEditorC
5858
label: nls.localize('neverShowAgain', "OK. Never show again"),
5959
run: () => {
6060
this._isDisabled = true;
61-
this._storageService.store('editor.neverPromptForLargeFiles', true, StorageScope.GLOBAL);
61+
this._nextStorage2Service.set('editor.neverPromptForLargeFiles', true, StorageScope.GLOBAL);
6262
}
6363
},
6464
{

0 commit comments

Comments
 (0)