Merge from vscode 6e530127a1bb8ffbd1bfb77dc680c321dc0d71f5 (#6844)

This commit is contained in:
Anthony Dresser
2019-08-20 21:07:47 -07:00
committed by GitHub
parent 1f00249646
commit ecb80f14f0
221 changed files with 3140 additions and 1552 deletions

View File

@@ -37,7 +37,7 @@ export class BrowserStorageService extends Disposable implements IStorageService
private workspaceStorageFile: URI;
private initializePromise: Promise<void>;
private periodicSaveScheduler = this._register(new RunOnceScheduler(() => this.saveState(), 5000));
private periodicSaveScheduler = this._register(new RunOnceScheduler(() => this.collectState(), 5000));
get hasPendingUpdate(): boolean {
return this.globalStorageDatabase.hasPendingUpdate || this.workspaceStorageDatabase.hasPendingUpdate;
@@ -57,14 +57,19 @@ export class BrowserStorageService extends Disposable implements IStorageService
this.periodicSaveScheduler.schedule();
}
private saveState(): void {
private collectState(): void {
runWhenIdle(() => {
// this event will potentially cause new state to be stored
// since new state will only be created while the document
// has focus, one optimization is to not run this when the
// document has no focus, assuming that state has not changed
if (document.hasFocus()) {
//
// another optimization is to not collect more state if we
// have a pending update already running which indicates
// that the connection is either slow or disconnected and
// thus unhealthy.
if (document.hasFocus() && !this.hasPendingUpdate) {
this._onWillSaveState.fire({ reason: WillSaveStateReason.NONE });
}
@@ -197,7 +202,7 @@ export class FileStorageDatabase extends Disposable implements IStorageDatabase
this._register(this.fileService.watch(this.file));
this._register(this.fileService.onFileChanges(e => {
if (document.hasFocus()) {
return; // ignore changes from ourselves by checking for focus
return; // optimization: ignore changes from ourselves by checking for focus
}
if (!e.contains(this.file, FileChangeType.UPDATED)) {
@@ -251,15 +256,17 @@ export class FileStorageDatabase extends Disposable implements IStorageDatabase
await this.pendingUpdate;
this._hasPendingUpdate = true;
this.pendingUpdate = (async () => {
try {
this._hasPendingUpdate = true;
await this.fileService.writeFile(this.file, VSBuffer.fromString(JSON.stringify(mapToSerializable(items))));
this.pendingUpdate = this.fileService.writeFile(this.file, VSBuffer.fromString(JSON.stringify(mapToSerializable(items))))
.then(() => {
this.ensureWatching(); // now that the file must exist, ensure we watch it for changes
})
.finally(() => {
} finally {
this._hasPendingUpdate = false;
});
}
})();
return this.pendingUpdate;
}

View File

@@ -5,7 +5,7 @@
import { IChannel, IServerChannel } from 'vs/base/parts/ipc/common/ipc';
import { Event, Emitter } from 'vs/base/common/event';
import { StorageMainService, IStorageChangeEvent } from 'vs/platform/storage/node/storageMainService';
import { IStorageChangeEvent, IStorageMainService } from 'vs/platform/storage/node/storageMainService';
import { IUpdateRequest, IStorageDatabase, IStorageItemsChangeEvent } from 'vs/base/parts/storage/common/storage';
import { mapToSerializable, serializableToMap, values } from 'vs/base/common/map';
import { Disposable, IDisposable, dispose } from 'vs/base/common/lifecycle';
@@ -38,7 +38,7 @@ export class GlobalStorageDatabaseChannel extends Disposable implements IServerC
constructor(
private logService: ILogService,
private storageMainService: StorageMainService
private storageMainService: IStorageMainService
) {
super();
@@ -203,4 +203,4 @@ export class GlobalStorageDatabaseChannelClient extends Disposable implements IS
dispose(this.onDidChangeItemsOnMainListener);
}
}
}

View File

@@ -34,6 +34,16 @@ export interface IStorageMainService {
*/
readonly onWillSaveState: Event<void>;
/**
* Access to all cached items of this storage service.
*/
readonly items: Map<string, string>;
/**
* Required call to ensure the service can be used.
*/
initialize(): Promise<void>;
/**
* Retrieve an element stored with the given key from storage. Use
* the provided defaultValue if the element is null or undefined.