diff --git a/src/indexer/IndexManager.ts b/src/indexer/IndexManager.ts index 3bb1acf..2767a26 100644 --- a/src/indexer/IndexManager.ts +++ b/src/indexer/IndexManager.ts @@ -37,6 +37,8 @@ type IndexerDataMap = { }; class IndexManager { + private static readonly INDEX_BATCH_SIZE = 50; + protected indexers: IndexerInstance[] = []; protected indexStorage: IndexStorage; @@ -86,23 +88,27 @@ class IndexManager { let doneCount = 0; const totalCount = files.length; - await Promise.all( - files.map(async file => { - const data = await indexer.indexFile(file); + for (let i = 0; i < files.length; i += IndexManager.INDEX_BATCH_SIZE) { + const batch = files.slice(i, i + IndexManager.INDEX_BATCH_SIZE); + + await Promise.all( + batch.map(async file => { + const data = await indexer.indexFile(file); - if (data !== undefined) { - indexData.set(file.fsPath, data); - } + if (data !== undefined) { + indexData.set(file.fsPath, data); + } - doneCount++; - const pct = Math.round((doneCount / totalCount) * 100); + doneCount++; + const pct = Math.round((doneCount / totalCount) * 100); - progress.report({ - message: `Indexing - ${indexer.getName()} [${doneCount}/${totalCount}]`, - increment: pct, - }); - }) - ); + progress.report({ + message: `Indexing - ${indexer.getName()} [${doneCount}/${totalCount}]`, + increment: pct, + }); + }) + ); + } this.indexStorage.set(workspaceFolder, indexer.getId(), indexData); this.indexStorage.saveIndex(workspaceFolder, indexer.getId(), indexer.getVersion()); diff --git a/src/indexer/IndexRunner.ts b/src/indexer/IndexRunner.ts index 87348b3..83154a0 100644 --- a/src/indexer/IndexRunner.ts +++ b/src/indexer/IndexRunner.ts @@ -1,17 +1,19 @@ import * as vscode from 'vscode'; import IndexManager from './IndexManager'; +import ExtensionState from 'common/ExtensionState'; +import Common from 'util/Common'; class IndexRunner { public async indexWorkspace(force: boolean = false): Promise { - if (!vscode.workspace.workspaceFolders) { + if (ExtensionState.magentoWorkspaces.length === 0) { return; } - for (const workspaceFolder of vscode.workspace.workspaceFolders) { + for (const workspaceFolder of ExtensionState.magentoWorkspaces) { await vscode.window.withProgress( { location: vscode.ProgressLocation.Window, - title: '[Magento Toolbox]', + title: `Magento Toolbox v${Common.getVersion()}`, }, async progress => { await IndexManager.indexWorkspace(workspaceFolder, progress, force); diff --git a/src/util/Common.ts b/src/util/Common.ts index 94a7bab..1cb416e 100644 --- a/src/util/Common.ts +++ b/src/util/Common.ts @@ -19,4 +19,8 @@ export default class Common { return undefined; } + + public static getVersion(): string { + return ExtensionState.context.extension.packageJSON.version; + } }