You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-25 05:23:13 +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:
@@ -282,4 +282,30 @@ describe("utils", function() {
|
||||
expect(target.nonenumerableProp).toBe(undefined);
|
||||
});
|
||||
});
|
||||
|
||||
describe("chunkPromises", function() {
|
||||
it("should execute promises in chunks", async function() {
|
||||
let promiseCount = 0;
|
||||
|
||||
function fn1() {
|
||||
return new Promise(async function(resolve, reject) {
|
||||
await utils.sleep(1);
|
||||
expect(promiseCount).toEqual(0);
|
||||
++promiseCount;
|
||||
resolve();
|
||||
});
|
||||
}
|
||||
|
||||
function fn2() {
|
||||
return new Promise(function(resolve, reject) {
|
||||
expect(promiseCount).toEqual(1);
|
||||
++promiseCount;
|
||||
resolve();
|
||||
});
|
||||
}
|
||||
|
||||
await utils.chunkPromises([fn1, fn2], 1);
|
||||
expect(promiseCount).toEqual(2);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user