[Glitch] Fix ValidationError when loading many collections at once

Port 2b6b2fcb6f to glitch-soc

Signed-off-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
diondiondion
2026-06-07 14:37:47 +02:00
committed by Claire
parent 45a21db621
commit cdc2d91d43
2 changed files with 24 additions and 4 deletions
@@ -0,0 +1,15 @@
/**
* Splits a long array so that the resulting nested arrays
* never exceed the `maxLength` provided.
* Useful when dealing with endpoints that accept a limited number
* of parameters
*/
export function batchArray<T>(array: T[], maxLength: number) {
const result: T[][] = [];
for (let i = 0; i < array.length; i += maxLength) {
result.push(array.slice(i, i + maxLength));
}
return result;
}