[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:
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user