mirror of
https://github.com/Microsoft/vscode
synced 2024-09-13 13:46:13 +00:00
sqlite - reduce pressure on storage
This commit is contained in:
parent
d68c05c3d9
commit
6187c66727
|
@ -8,7 +8,6 @@ import { LRUCache, TernarySearchTree } from 'vs/base/common/map';
|
|||
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
|
||||
import { ITextModel } from 'vs/editor/common/model';
|
||||
import { IPosition } from 'vs/editor/common/core/position';
|
||||
import { RunOnceScheduler } from 'vs/base/common/async';
|
||||
import { CompletionItemKind, completionKindFromLegacyString } from 'vs/editor/common/modes';
|
||||
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
|
||||
import { Disposable } from 'vs/base/common/lifecycle';
|
||||
|
@ -200,7 +199,6 @@ export class SuggestMemories extends Disposable {
|
|||
|
||||
private _mode: MemMode;
|
||||
private _strategy: Memory;
|
||||
private readonly _persistSoon: RunOnceScheduler;
|
||||
|
||||
constructor(
|
||||
editor: ICodeEditor,
|
||||
|
@ -208,10 +206,9 @@ export class SuggestMemories extends Disposable {
|
|||
) {
|
||||
super();
|
||||
|
||||
this._persistSoon = this._register(new RunOnceScheduler(() => this._flush(), 3000));
|
||||
this._setMode(editor.getConfiguration().contribInfo.suggestSelection);
|
||||
this._register(editor.onDidChangeConfiguration(e => e.contribInfo && this._setMode(editor.getConfiguration().contribInfo.suggestSelection)));
|
||||
this._register(_storageService.onWillClose(() => this._flush()));
|
||||
this._register(_storageService.onWillClose(() => this._saveState()));
|
||||
}
|
||||
|
||||
private _setMode(mode: MemMode): void {
|
||||
|
@ -233,15 +230,14 @@ export class SuggestMemories extends Disposable {
|
|||
|
||||
memorize(model: ITextModel, pos: IPosition, item: ICompletionItem): void {
|
||||
this._strategy.memorize(model, pos, item);
|
||||
this._persistSoon.schedule();
|
||||
}
|
||||
|
||||
select(model: ITextModel, pos: IPosition, items: ICompletionItem[]): number {
|
||||
return this._strategy.select(model, pos, items);
|
||||
}
|
||||
|
||||
private _flush() {
|
||||
private _saveState() {
|
||||
const raw = JSON.stringify(this._strategy);
|
||||
this._storageService.store(`${this._storagePrefix}/${this._mode}`, raw, StorageScope.WORKSPACE);
|
||||
this._storageService.store(`${this._storagePrefix}/${this._mode}`, raw, StorageScope.WORKSPACE); //
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ import { SidebarPart } from 'vs/workbench/browser/parts/sidebar/sidebarPart';
|
|||
import { PanelPart } from 'vs/workbench/browser/parts/panel/panelPart';
|
||||
import { StatusbarPart } from 'vs/workbench/browser/parts/statusbar/statusbarPart';
|
||||
import { getZoomFactor } from 'vs/base/browser/browser';
|
||||
import { RunOnceScheduler } from 'vs/base/common/async';
|
||||
|
||||
const TITLE_BAR_HEIGHT = isMacintosh ? 22 : 30;
|
||||
const STATUS_BAR_HEIGHT = 22;
|
||||
|
@ -67,6 +68,8 @@ export class WorkbenchLayout extends Disposable implements IVerticalSashLayoutPr
|
|||
private _panelHeight: number;
|
||||
private _panelWidth: number;
|
||||
|
||||
private saveStateScheduler: RunOnceScheduler;
|
||||
|
||||
constructor(
|
||||
private parent: HTMLElement,
|
||||
private workbenchContainer: HTMLElement,
|
||||
|
@ -99,6 +102,9 @@ export class WorkbenchLayout extends Disposable implements IVerticalSashLayoutPr
|
|||
this.sashXTwo = new Sash(this.workbenchContainer, this);
|
||||
this.sashY = new Sash(this.workbenchContainer, this, { orientation: Orientation.HORIZONTAL });
|
||||
|
||||
// State scheduler
|
||||
this.saveStateScheduler = new RunOnceScheduler(() => this.saveState(), 1000);
|
||||
|
||||
this.registerListeners();
|
||||
}
|
||||
|
||||
|
@ -115,6 +121,10 @@ export class WorkbenchLayout extends Disposable implements IVerticalSashLayoutPr
|
|||
private registerListeners(): void {
|
||||
this._register(this.themeService.onThemeChange(_ => this.layout()));
|
||||
this._register(this.parts.editor.onDidSizeConstraintsChange(() => this.onDidEditorSizeConstraintsChange()));
|
||||
this._register(this.storageService.onWillClose(() => {
|
||||
this.saveStateScheduler.dispose();
|
||||
this.saveState();
|
||||
}));
|
||||
|
||||
this.registerSashListeners();
|
||||
}
|
||||
|
@ -372,20 +382,21 @@ export class WorkbenchLayout extends Disposable implements IVerticalSashLayoutPr
|
|||
}));
|
||||
|
||||
this._register(this.sashXOne.onDidEnd(() => {
|
||||
this.storageService.store(WorkbenchLayout.sashXOneWidthSettingsKey, this.sidebarWidth, StorageScope.GLOBAL);
|
||||
this.saveStateScheduler.schedule();
|
||||
}));
|
||||
|
||||
this._register(this.sashY.onDidEnd(() => {
|
||||
this.storageService.store(WorkbenchLayout.sashYHeightSettingsKey, this.panelHeight, StorageScope.GLOBAL);
|
||||
this.saveStateScheduler.schedule();
|
||||
}));
|
||||
|
||||
this._register(this.sashXTwo.onDidEnd(() => {
|
||||
this.storageService.store(WorkbenchLayout.sashXTwoWidthSettingsKey, this.panelWidth, StorageScope.GLOBAL);
|
||||
this.saveStateScheduler.schedule();
|
||||
}));
|
||||
|
||||
this._register(this.sashY.onDidReset(() => {
|
||||
this.panelHeight = this.sidebarHeight * DEFAULT_PANEL_SIZE_COEFFICIENT;
|
||||
this.storageService.store(WorkbenchLayout.sashYHeightSettingsKey, this.panelHeight, StorageScope.GLOBAL);
|
||||
|
||||
this.saveStateScheduler.schedule();
|
||||
|
||||
this.layout();
|
||||
}));
|
||||
|
@ -394,20 +405,22 @@ export class WorkbenchLayout extends Disposable implements IVerticalSashLayoutPr
|
|||
let activeViewlet = this.viewletService.getActiveViewlet();
|
||||
let optimalWidth = activeViewlet && activeViewlet.getOptimalWidth();
|
||||
this.sidebarWidth = Math.max(optimalWidth, DEFAULT_SIDEBAR_PART_WIDTH);
|
||||
this.storageService.store(WorkbenchLayout.sashXOneWidthSettingsKey, this.sidebarWidth, StorageScope.GLOBAL);
|
||||
|
||||
this.saveStateScheduler.schedule();
|
||||
|
||||
this.partService.setSideBarHidden(false).then(() => this.layout());
|
||||
}));
|
||||
|
||||
this._register(this.sashXTwo.onDidReset(() => {
|
||||
this.panelWidth = (this.workbenchSize.width - this.sidebarWidth - this.activitybarWidth) * DEFAULT_PANEL_SIZE_COEFFICIENT;
|
||||
this.storageService.store(WorkbenchLayout.sashXTwoWidthSettingsKey, this.panelWidth, StorageScope.GLOBAL);
|
||||
|
||||
this.saveStateScheduler.schedule();
|
||||
|
||||
this.layout();
|
||||
}));
|
||||
}
|
||||
|
||||
layout(options?: ILayoutOptions): void {
|
||||
layout(options?: ILayoutOptions): void { //
|
||||
this.workbenchSize = getClientArea(this.parent);
|
||||
|
||||
const isActivityBarHidden = !this.partService.isVisible(Parts.ACTIVITYBAR_PART);
|
||||
|
@ -476,8 +489,6 @@ export class WorkbenchLayout extends Disposable implements IVerticalSashLayoutPr
|
|||
}
|
||||
}
|
||||
|
||||
this.storageService.store(WorkbenchLayout.panelSizeBeforeMaximizedKey, this.panelSizeBeforeMaximized, StorageScope.GLOBAL);
|
||||
|
||||
const panelDimension = new Dimension(panelWidth, panelHeight);
|
||||
|
||||
// Editor
|
||||
|
@ -532,16 +543,13 @@ export class WorkbenchLayout extends Disposable implements IVerticalSashLayoutPr
|
|||
|
||||
if (!isSidebarHidden) {
|
||||
this.sidebarWidth = sidebarSize.width;
|
||||
this.storageService.store(WorkbenchLayout.sashXOneWidthSettingsKey, this.sidebarWidth, StorageScope.GLOBAL);
|
||||
}
|
||||
|
||||
if (!isPanelHidden) {
|
||||
if (panelPosition === Position.BOTTOM) {
|
||||
this.panelHeight = panelDimension.height;
|
||||
this.storageService.store(WorkbenchLayout.sashYHeightSettingsKey, this.panelHeight, StorageScope.GLOBAL);
|
||||
} else {
|
||||
this.panelWidth = panelDimension.width;
|
||||
this.storageService.store(WorkbenchLayout.sashXTwoWidthSettingsKey, this.panelWidth, StorageScope.GLOBAL);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -647,6 +655,9 @@ export class WorkbenchLayout extends Disposable implements IVerticalSashLayoutPr
|
|||
|
||||
// Propagate to Context View
|
||||
this.contextViewService.layout();
|
||||
|
||||
// Schedule save state
|
||||
this.saveStateScheduler.schedule();
|
||||
}
|
||||
|
||||
getVerticalSashTop(sash: Sash): number {
|
||||
|
@ -748,4 +759,13 @@ export class WorkbenchLayout extends Disposable implements IVerticalSashLayoutPr
|
|||
this.layout();
|
||||
}
|
||||
}
|
||||
|
||||
private saveState(): void {
|
||||
this.storageService.store(WorkbenchLayout.sashXOneWidthSettingsKey, this.sidebarWidth, StorageScope.GLOBAL);
|
||||
|
||||
this.storageService.store(WorkbenchLayout.sashYHeightSettingsKey, this.panelHeight, StorageScope.GLOBAL);
|
||||
this.storageService.store(WorkbenchLayout.sashXTwoWidthSettingsKey, this.panelWidth, StorageScope.GLOBAL);
|
||||
|
||||
this.storageService.store(WorkbenchLayout.panelSizeBeforeMaximizedKey, this.panelSizeBeforeMaximized, StorageScope.GLOBAL);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ class PartsSplash {
|
|||
debounceEvent(anyEvent<any>(
|
||||
onDidChangeFullscreen,
|
||||
_partService.onEditorLayout
|
||||
), () => { }, 150)(this._savePartsSplash, this, this._disposables);
|
||||
), () => { }, 800)(this._savePartsSplash, this, this._disposables);
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
|
|
Loading…
Reference in a new issue