Skip to content

Commit 7d28d6b

Browse files
fix: only index magento workspaces; index files in batches
1 parent aad3da5 commit 7d28d6b

File tree

3 files changed

+29
-17
lines changed

3 files changed

+29
-17
lines changed

src/indexer/IndexManager.ts

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ type IndexerDataMap = {
3737
};
3838

3939
class IndexManager {
40+
private static readonly INDEX_BATCH_SIZE = 50;
41+
4042
protected indexers: IndexerInstance[] = [];
4143
protected indexStorage: IndexStorage;
4244

@@ -86,23 +88,27 @@ class IndexManager {
8688
let doneCount = 0;
8789
const totalCount = files.length;
8890

89-
await Promise.all(
90-
files.map(async file => {
91-
const data = await indexer.indexFile(file);
91+
for (let i = 0; i < files.length; i += IndexManager.INDEX_BATCH_SIZE) {
92+
const batch = files.slice(i, i + IndexManager.INDEX_BATCH_SIZE);
93+
94+
await Promise.all(
95+
batch.map(async file => {
96+
const data = await indexer.indexFile(file);
9297

93-
if (data !== undefined) {
94-
indexData.set(file.fsPath, data);
95-
}
98+
if (data !== undefined) {
99+
indexData.set(file.fsPath, data);
100+
}
96101

97-
doneCount++;
98-
const pct = Math.round((doneCount / totalCount) * 100);
102+
doneCount++;
103+
const pct = Math.round((doneCount / totalCount) * 100);
99104

100-
progress.report({
101-
message: `Indexing - ${indexer.getName()} [${doneCount}/${totalCount}]`,
102-
increment: pct,
103-
});
104-
})
105-
);
105+
progress.report({
106+
message: `Indexing - ${indexer.getName()} [${doneCount}/${totalCount}]`,
107+
increment: pct,
108+
});
109+
})
110+
);
111+
}
106112

107113
this.indexStorage.set(workspaceFolder, indexer.getId(), indexData);
108114
this.indexStorage.saveIndex(workspaceFolder, indexer.getId(), indexer.getVersion());

src/indexer/IndexRunner.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
import * as vscode from 'vscode';
22
import IndexManager from './IndexManager';
3+
import ExtensionState from 'common/ExtensionState';
4+
import Common from 'util/Common';
35

46
class IndexRunner {
57
public async indexWorkspace(force: boolean = false): Promise<void> {
6-
if (!vscode.workspace.workspaceFolders) {
8+
if (ExtensionState.magentoWorkspaces.length === 0) {
79
return;
810
}
911

10-
for (const workspaceFolder of vscode.workspace.workspaceFolders) {
12+
for (const workspaceFolder of ExtensionState.magentoWorkspaces) {
1113
await vscode.window.withProgress(
1214
{
1315
location: vscode.ProgressLocation.Window,
14-
title: '[Magento Toolbox]',
16+
title: `Magento Toolbox v${Common.getVersion()}`,
1517
},
1618
async progress => {
1719
await IndexManager.indexWorkspace(workspaceFolder, progress, force);

src/util/Common.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,8 @@ export default class Common {
1919

2020
return undefined;
2121
}
22+
23+
public static getVersion(): string {
24+
return ExtensionState.context.extension.packageJSON.version;
25+
}
2226
}

0 commit comments

Comments
 (0)