fix: file download large repo

This commit is contained in:
tdurieux
2026-05-12 21:00:47 +03:00
parent 898f18919e
commit e73ad48115
+15 -25
View File
@@ -460,10 +460,13 @@ export default class GitHubStream extends GitHubBase {
} }
} }
const fetchSubtree = async ( const queue = [...subtrees];
entry: { sha: string; parentPath: string } while (queue.length > 0) {
) => { const batch = queue.splice(0, GH_API_CONCURRENCY);
const data = await this.getGHTree(oct, token, entry.sha, count, { const batchResults = await pMap(
batch,
async (entry) => {
const treeData = await this.getGHTree(oct, token, entry.sha, count, {
recursive: true, recursive: true,
callback: () => { callback: () => {
if (progress) { if (progress) {
@@ -471,11 +474,9 @@ export default class GitHubStream extends GitHubBase {
} }
}, },
}); });
if (!data.truncated) { if (!treeData.truncated) {
return this.tree2Tree(data.tree, entry.parentPath); return { files: this.tree2Tree(treeData.tree, entry.parentPath), children: [] as typeof subtrees };
} }
// Subtree was truncated — break it down by fetching non-recursively
// and then recursing into each child subtree individually.
logger.info( logger.info(
`Tree truncated for ${entry.parentPath}, breaking down into subtrees` `Tree truncated for ${entry.parentPath}, breaking down into subtrees`
); );
@@ -490,8 +491,7 @@ export default class GitHubStream extends GitHubBase {
if (shallow.truncated) { if (shallow.truncated) {
this._truncatedFolders.push(entry.parentPath); this._truncatedFolders.push(entry.parentPath);
} }
const files = this.tree2Tree(shallow.tree, entry.parentPath); const children = shallow.tree
const childSubtrees = shallow.tree
.filter( .filter(
(f): f is typeof f & { sha: string; path: string } => (f): f is typeof f & { sha: string; path: string } =>
f.type === "tree" && !!f.path && !!f.sha f.type === "tree" && !!f.path && !!f.sha
@@ -500,24 +500,14 @@ export default class GitHubStream extends GitHubBase {
sha: f.sha, sha: f.sha,
parentPath: path.join(entry.parentPath, f.path), parentPath: path.join(entry.parentPath, f.path),
})); }));
const childResults = await pMap( return { files: this.tree2Tree(shallow.tree, entry.parentPath), children };
childSubtrees, },
(child) => fetchSubtree(child),
GH_API_CONCURRENCY GH_API_CONCURRENCY
); );
for (const childFiles of childResults) { for (const result of batchResults) {
files.push(...childFiles); output.push(...result.files);
queue.push(...result.children);
} }
return files;
};
const results = await pMap(
subtrees,
(entry) => fetchSubtree(entry),
GH_API_CONCURRENCY
);
for (const files of results) {
output.push(...files);
} }
return output; return output;
} }