Add segmentation to reports list to fix it (#3772)

This commit is contained in:
Prospector
2025-06-11 15:22:47 -07:00
committed by GitHub
parent ee8ee7af82
commit 6741aba880
3 changed files with 32 additions and 26 deletions

View File

@@ -0,0 +1,26 @@
function segmentData<T>(data: T[], segmentSize: number): T[][] {
return data.reduce((acc: T[][], curr, index) => {
const segment = Math.floor(index / segmentSize);
if (!acc[segment]) {
acc[segment] = [];
}
acc[segment].push(curr);
return acc;
}, []);
}
export function fetchSegmented<T>(
data: T[],
createUrl: (ids: T[]) => string,
options = {},
segmentSize = 800,
): Promise<any> {
return Promise.all(
segmentData(data, segmentSize).map((ids) => useBaseFetch(createUrl(ids), options)),
).then((results) => results.flat());
}
export function asEncodedJsonArray<T>(data: T[]): string {
return encodeURIComponent(JSON.stringify(data));
}