You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-26 17:03:12 +03:00
Download device keys in chunks of 250
Depending on the number of users in the request, the server might overload. To prevent this, the download is broken into chunks of 250 users each. Additionally, no more than 3 requests are kicked off at the same time to avoid running into rate limiting. Responses are processed once all chunks have been downloaded. Fixes: #1619 Signed-off-by: Johannes Marbach <n0-0ne+github@mailbox.org>
This commit is contained in:
@@ -745,6 +745,15 @@ export function promiseTry<T>(fn: () => T): Promise<T> {
|
||||
return new Promise((resolve) => resolve(fn()));
|
||||
}
|
||||
|
||||
// Creates and awaits all promises, running no more than `chunkSize` at the same time
|
||||
export async function chunkPromises<T>(fns: (() => Promise<T>)[], chunkSize: number): Promise<T[]> {
|
||||
const results: T[] = [];
|
||||
for (let i = 0; i < fns.length; i += chunkSize) {
|
||||
results.push(...(await Promise.all(fns.slice(i, i + chunkSize).map(fn => fn()))));
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
// We need to be able to access the Node.js crypto library from within the
|
||||
// Matrix SDK without needing to `require("crypto")`, which will fail in
|
||||
// browsers. So `index.ts` will call `setCrypto` to store it, and when we need
|
||||
|
||||
Reference in New Issue
Block a user