From 7c0aa47d19e2f88897773360b08d7c76f8c069b3 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Wed, 21 Nov 2018 18:08:38 +0100 Subject: [PATCH] storage - add a hint for speeding up Storage#init() --- src/vs/base/node/storage.ts | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/vs/base/node/storage.ts b/src/vs/base/node/storage.ts index fb5c7a39185..bd19271e8d6 100644 --- a/src/vs/base/node/storage.ts +++ b/src/vs/base/node/storage.ts @@ -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 = new Set(); private pendingInserts: Map = 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; }); -- GitLab