Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 20 additions & 14 deletions src/indexer/IndexManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ type IndexerDataMap = {
};

class IndexManager {
private static readonly INDEX_BATCH_SIZE = 50;

protected indexers: IndexerInstance[] = [];
protected indexStorage: IndexStorage;

Expand Down Expand Up @@ -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());
Expand Down
8 changes: 5 additions & 3 deletions src/indexer/IndexRunner.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
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);
Expand Down
4 changes: 4 additions & 0 deletions src/util/Common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ export default class Common {

return undefined;
}

public static getVersion(): string {
return ExtensionState.context.extension.packageJSON.version;
}
}