Skip to content

Commit 6187c66

Browse files
author
Benjamin Pasero
committed
sqlite - reduce pressure on storage
1 parent d68c05c commit 6187c66

3 files changed

Lines changed: 36 additions & 20 deletions

File tree

src/vs/editor/contrib/suggest/suggestMemory.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { LRUCache, TernarySearchTree } from 'vs/base/common/map';
88
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
99
import { ITextModel } from 'vs/editor/common/model';
1010
import { IPosition } from 'vs/editor/common/core/position';
11-
import { RunOnceScheduler } from 'vs/base/common/async';
1211
import { CompletionItemKind, completionKindFromLegacyString } from 'vs/editor/common/modes';
1312
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
1413
import { Disposable } from 'vs/base/common/lifecycle';
@@ -200,18 +199,16 @@ export class SuggestMemories extends Disposable {
200199

201200
private _mode: MemMode;
202201
private _strategy: Memory;
203-
private readonly _persistSoon: RunOnceScheduler;
204202

205203
constructor(
206204
editor: ICodeEditor,
207205
@IStorageService private readonly _storageService: IStorageService,
208206
) {
209207
super();
210208

211-
this._persistSoon = this._register(new RunOnceScheduler(() => this._flush(), 3000));
212209
this._setMode(editor.getConfiguration().contribInfo.suggestSelection);
213210
this._register(editor.onDidChangeConfiguration(e => e.contribInfo && this._setMode(editor.getConfiguration().contribInfo.suggestSelection)));
214-
this._register(_storageService.onWillClose(() => this._flush()));
211+
this._register(_storageService.onWillClose(() => this._saveState()));
215212
}
216213

217214
private _setMode(mode: MemMode): void {
@@ -233,15 +230,14 @@ export class SuggestMemories extends Disposable {
233230

234231
memorize(model: ITextModel, pos: IPosition, item: ICompletionItem): void {
235232
this._strategy.memorize(model, pos, item);
236-
this._persistSoon.schedule();
237233
}
238234

239235
select(model: ITextModel, pos: IPosition, items: ICompletionItem[]): number {
240236
return this._strategy.select(model, pos, items);
241237
}
242238

243-
private _flush() {
239+
private _saveState() {
244240
const raw = JSON.stringify(this._strategy);
245-
this._storageService.store(`${this._storagePrefix}/${this._mode}`, raw, StorageScope.WORKSPACE);
241+
this._storageService.store(`${this._storagePrefix}/${this._mode}`, raw, StorageScope.WORKSPACE); //
246242
}
247243
}

src/vs/workbench/browser/layout.ts

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { SidebarPart } from 'vs/workbench/browser/parts/sidebar/sidebarPart';
2525
import { PanelPart } from 'vs/workbench/browser/parts/panel/panelPart';
2626
import { StatusbarPart } from 'vs/workbench/browser/parts/statusbar/statusbarPart';
2727
import { getZoomFactor } from 'vs/base/browser/browser';
28+
import { RunOnceScheduler } from 'vs/base/common/async';
2829

2930
const TITLE_BAR_HEIGHT = isMacintosh ? 22 : 30;
3031
const STATUS_BAR_HEIGHT = 22;
@@ -67,6 +68,8 @@ export class WorkbenchLayout extends Disposable implements IVerticalSashLayoutPr
6768
private _panelHeight: number;
6869
private _panelWidth: number;
6970

71+
private saveStateScheduler: RunOnceScheduler;
72+
7073
constructor(
7174
private parent: HTMLElement,
7275
private workbenchContainer: HTMLElement,
@@ -99,6 +102,9 @@ export class WorkbenchLayout extends Disposable implements IVerticalSashLayoutPr
99102
this.sashXTwo = new Sash(this.workbenchContainer, this);
100103
this.sashY = new Sash(this.workbenchContainer, this, { orientation: Orientation.HORIZONTAL });
101104

105+
// State scheduler
106+
this.saveStateScheduler = new RunOnceScheduler(() => this.saveState(), 1000);
107+
102108
this.registerListeners();
103109
}
104110

@@ -115,6 +121,10 @@ export class WorkbenchLayout extends Disposable implements IVerticalSashLayoutPr
115121
private registerListeners(): void {
116122
this._register(this.themeService.onThemeChange(_ => this.layout()));
117123
this._register(this.parts.editor.onDidSizeConstraintsChange(() => this.onDidEditorSizeConstraintsChange()));
124+
this._register(this.storageService.onWillClose(() => {
125+
this.saveStateScheduler.dispose();
126+
this.saveState();
127+
}));
118128

119129
this.registerSashListeners();
120130
}
@@ -372,20 +382,21 @@ export class WorkbenchLayout extends Disposable implements IVerticalSashLayoutPr
372382
}));
373383

374384
this._register(this.sashXOne.onDidEnd(() => {
375-
this.storageService.store(WorkbenchLayout.sashXOneWidthSettingsKey, this.sidebarWidth, StorageScope.GLOBAL);
385+
this.saveStateScheduler.schedule();
376386
}));
377387

378388
this._register(this.sashY.onDidEnd(() => {
379-
this.storageService.store(WorkbenchLayout.sashYHeightSettingsKey, this.panelHeight, StorageScope.GLOBAL);
389+
this.saveStateScheduler.schedule();
380390
}));
381391

382392
this._register(this.sashXTwo.onDidEnd(() => {
383-
this.storageService.store(WorkbenchLayout.sashXTwoWidthSettingsKey, this.panelWidth, StorageScope.GLOBAL);
393+
this.saveStateScheduler.schedule();
384394
}));
385395

386396
this._register(this.sashY.onDidReset(() => {
387397
this.panelHeight = this.sidebarHeight * DEFAULT_PANEL_SIZE_COEFFICIENT;
388-
this.storageService.store(WorkbenchLayout.sashYHeightSettingsKey, this.panelHeight, StorageScope.GLOBAL);
398+
399+
this.saveStateScheduler.schedule();
389400

390401
this.layout();
391402
}));
@@ -394,20 +405,22 @@ export class WorkbenchLayout extends Disposable implements IVerticalSashLayoutPr
394405
let activeViewlet = this.viewletService.getActiveViewlet();
395406
let optimalWidth = activeViewlet && activeViewlet.getOptimalWidth();
396407
this.sidebarWidth = Math.max(optimalWidth, DEFAULT_SIDEBAR_PART_WIDTH);
397-
this.storageService.store(WorkbenchLayout.sashXOneWidthSettingsKey, this.sidebarWidth, StorageScope.GLOBAL);
408+
409+
this.saveStateScheduler.schedule();
398410

399411
this.partService.setSideBarHidden(false).then(() => this.layout());
400412
}));
401413

402414
this._register(this.sashXTwo.onDidReset(() => {
403415
this.panelWidth = (this.workbenchSize.width - this.sidebarWidth - this.activitybarWidth) * DEFAULT_PANEL_SIZE_COEFFICIENT;
404-
this.storageService.store(WorkbenchLayout.sashXTwoWidthSettingsKey, this.panelWidth, StorageScope.GLOBAL);
416+
417+
this.saveStateScheduler.schedule();
405418

406419
this.layout();
407420
}));
408421
}
409422

410-
layout(options?: ILayoutOptions): void {
423+
layout(options?: ILayoutOptions): void { //
411424
this.workbenchSize = getClientArea(this.parent);
412425

413426
const isActivityBarHidden = !this.partService.isVisible(Parts.ACTIVITYBAR_PART);
@@ -476,8 +489,6 @@ export class WorkbenchLayout extends Disposable implements IVerticalSashLayoutPr
476489
}
477490
}
478491

479-
this.storageService.store(WorkbenchLayout.panelSizeBeforeMaximizedKey, this.panelSizeBeforeMaximized, StorageScope.GLOBAL);
480-
481492
const panelDimension = new Dimension(panelWidth, panelHeight);
482493

483494
// Editor
@@ -532,16 +543,13 @@ export class WorkbenchLayout extends Disposable implements IVerticalSashLayoutPr
532543

533544
if (!isSidebarHidden) {
534545
this.sidebarWidth = sidebarSize.width;
535-
this.storageService.store(WorkbenchLayout.sashXOneWidthSettingsKey, this.sidebarWidth, StorageScope.GLOBAL);
536546
}
537547

538548
if (!isPanelHidden) {
539549
if (panelPosition === Position.BOTTOM) {
540550
this.panelHeight = panelDimension.height;
541-
this.storageService.store(WorkbenchLayout.sashYHeightSettingsKey, this.panelHeight, StorageScope.GLOBAL);
542551
} else {
543552
this.panelWidth = panelDimension.width;
544-
this.storageService.store(WorkbenchLayout.sashXTwoWidthSettingsKey, this.panelWidth, StorageScope.GLOBAL);
545553
}
546554
}
547555

@@ -647,6 +655,9 @@ export class WorkbenchLayout extends Disposable implements IVerticalSashLayoutPr
647655

648656
// Propagate to Context View
649657
this.contextViewService.layout();
658+
659+
// Schedule save state
660+
this.saveStateScheduler.schedule();
650661
}
651662

652663
getVerticalSashTop(sash: Sash): number {
@@ -748,4 +759,13 @@ export class WorkbenchLayout extends Disposable implements IVerticalSashLayoutPr
748759
this.layout();
749760
}
750761
}
762+
763+
private saveState(): void {
764+
this.storageService.store(WorkbenchLayout.sashXOneWidthSettingsKey, this.sidebarWidth, StorageScope.GLOBAL);
765+
766+
this.storageService.store(WorkbenchLayout.sashYHeightSettingsKey, this.panelHeight, StorageScope.GLOBAL);
767+
this.storageService.store(WorkbenchLayout.sashXTwoWidthSettingsKey, this.panelWidth, StorageScope.GLOBAL);
768+
769+
this.storageService.store(WorkbenchLayout.panelSizeBeforeMaximizedKey, this.panelSizeBeforeMaximized, StorageScope.GLOBAL);
770+
}
751771
}

src/vs/workbench/parts/splash/electron-browser/partsSplash.contribution.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class PartsSplash {
4141
debounceEvent(anyEvent<any>(
4242
onDidChangeFullscreen,
4343
_partService.onEditorLayout
44-
), () => { }, 150)(this._savePartsSplash, this, this._disposables);
44+
), () => { }, 800)(this._savePartsSplash, this, this._disposables);
4545
}
4646

4747
dispose(): void {

0 commit comments

Comments
 (0)