提交 7c0aa47d 编写于 作者: B Benjamin Pasero

storage - add a hint for speeding up Storage#init()

上级 a0df045e
......@@ -13,9 +13,20 @@ import { basename } from 'path';
import { mark } from 'vs/base/common/performance';
import { rename, unlinkIgnoreError, copy, renameIgnoreError } from 'vs/base/node/pfs';
export enum StorageHint {
// A hint to the storage that the storage
// does not exist on disk yet. This allows
// the storage library to improve startup
// time by not checking the storage for data.
STORAGE_DOES_NOT_EXIST
}
export interface IStorageOptions {
path: string;
hint?: StorageHint;
logging?: IStorageLoggingOptions;
}
......@@ -73,7 +84,7 @@ export class Storage extends Disposable implements IStorage {
private pendingDeletes: Set<string> = new Set<string>();
private pendingInserts: Map<string, string> = new Map();
constructor(options: IStorageOptions) {
constructor(private options: IStorageOptions) {
super();
this.storage = new SQLiteStorageImpl(options);
......@@ -92,6 +103,13 @@ export class Storage extends Disposable implements IStorage {
this.state = StorageState.Initialized;
if (this.options.hint === StorageHint.STORAGE_DOES_NOT_EXIST) {
// return early if we know the storage file does not exist. this is a performance
// optimization to not load all items of the underlying storage if we know that
// there can be no items because the storage does not exist.
return Promise.resolve();
}
return this.storage.getItems().then(items => {
this.cache = items;
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册