Skip to content

Commit 4b7ca8c

Browse files
committed
Fix compactIndex infinite loop
1 parent c4614bc commit 4b7ca8c

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

runruby-worker/src/compactIndexSpecs.ts

+12-5
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,29 @@ const checkVersion = (options: GemDependency[], key: string, version: string): b
2121
if (match) {
2222
const operator = match[1];
2323
const majorVersion = parseInt(match[2]);
24-
if ((operator === '~>' && majorVersion < parseInt(version)) || (operator === '<' && majorVersion <= parseInt(version))) {
24+
if ((operator === "~>" && majorVersion < parseInt(version)) || (operator === "<" && majorVersion <= parseInt(version))) {
2525
return true;
2626
}
2727
}
2828
}
2929
}
3030
return false;
31-
}
31+
};
3232

3333
export default async (request: IRequest) => {
3434
const depth = request.query.depth;
3535
const maxDepth = typeof depth === "string" ? parseInt(depth) : 50;
3636
if (typeof request.query.gems !== "string") {
3737
throw new StatusError(422, "Gems required.");
3838
}
39+
40+
let subrequests = 0;
41+
3942
const gemNames = request.query.gems.split(",");
4043
const gemInfo: GemInfo[] = [];
4144
let completeGems: string[] = [];
42-
let remainingGems = gemNames.slice();
43-
let subrequests = 0;
45+
let remainingGems = gemNames.slice(0, REQUESTS_LIMIT - subrequests);
46+
const gemsOverflow = remainingGems.slice(REQUESTS_LIMIT - subrequests);
4447

4548
while (remainingGems.length > 0 && (subrequests + remainingGems.length) <= REQUESTS_LIMIT) {
4649
const depFetches = remainingGems.map(async (gem) => {
@@ -97,5 +100,9 @@ export default async (request: IRequest) => {
97100
remainingGems = nextGems.filter(gem => !completeGems.includes(gem));
98101
}
99102

100-
return { specs: gemInfo.map(Object.values), completeGems, remainingGems };
103+
return {
104+
specs: gemInfo.map(Object.values),
105+
completeGems,
106+
remainingGems: gemsOverflow.concat(remainingGems).filter(gem => !completeGems.includes(gem))
107+
};
101108
};

0 commit comments

Comments
 (0)