Fix #124276 batch markdown file requests (#124545)

* fix #124276 batch markdown file requests

* cleanup and modify return type

* Revert "cleanup and modify return type"

This reverts commit 62d62b4947.

* cleanup getAllMarkdownDocuments

* fix markdown batching

* fix var not being modified
cleanup function call
remove modulo use

* don't create a new array on each iteration

Co-authored-by: Matt Bierner <matb@microsoft.com>
This commit is contained in:
Nicholas Rayburn
2021-08-02 21:44:56 -05:00
committed by GitHub
parent 9539f015b1
commit 72d9aa625e

View File

@@ -28,10 +28,23 @@ class VSCodeWorkspaceMarkdownDocumentProvider extends Disposable implements Work
private readonly utf8Decoder = new TextDecoder('utf-8');
async getAllMarkdownDocuments() {
/**
* Reads and parses all .md documents in the workspace.
* Files are processed in batches, to keep the number of open files small.
*
* @returns Array of processed .md files.
*/
async getAllMarkdownDocuments(): Promise<SkinnyTextDocument[]> {
const maxConcurrent = 20;
const docList: SkinnyTextDocument[] = [];
const resources = await vscode.workspace.findFiles('**/*.md', '**/node_modules/**');
const docs = await Promise.all(resources.map(doc => this.getMarkdownDocument(doc)));
return docs.filter(doc => !!doc) as SkinnyTextDocument[];
for (let i = 0; i < resources.length; i += maxConcurrent) {
const resourceBatch = resources.slice(i, i + maxConcurrent);
const documentBatch = (await Promise.all(resourceBatch.map(this.getMarkdownDocument))).filter((doc) => !!doc) as SkinnyTextDocument[];
docList.push(...documentBatch);
}
return docList;
}
public get onDidChangeMarkdownDocument() {