Fix rate limit when reordering in space lobby (#2254)

* move can drop lobby item logic to hook

* add comment

* resolve rate limit when reordering space children
This commit is contained in:
Ajay Bura 2025-05-26 14:21:27 +05:30 committed by GitHub
parent 83057ebbd4
commit a23279e633
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 270 additions and 187 deletions

View file

@ -300,7 +300,7 @@ export const downloadEncryptedMedia = async (
export const rateLimitedActions = async <T, R = void>(
data: T[],
callback: (item: T) => Promise<R>,
callback: (item: T, index: number) => Promise<R>,
maxRetryCount?: number
) => {
let retryCount = 0;
@ -312,8 +312,8 @@ export const rateLimitedActions = async <T, R = void>(
setTimeout(resolve, ms);
});
const performAction = async (dataItem: T) => {
const [err] = await to<R, MatrixError>(callback(dataItem));
const performAction = async (dataItem: T, index: number) => {
const [err] = await to<R, MatrixError>(callback(dataItem, index));
if (err?.httpStatus === 429) {
if (retryCount === maxRetryCount) {
@ -321,11 +321,11 @@ export const rateLimitedActions = async <T, R = void>(
}
const waitMS = err.getRetryAfterMs() ?? 3000;
actionInterval = waitMS + 500;
actionInterval = waitMS * 1.5;
await sleepForMs(waitMS);
retryCount += 1;
await performAction(dataItem);
await performAction(dataItem, index);
}
};
@ -333,7 +333,7 @@ export const rateLimitedActions = async <T, R = void>(
const dataItem = data[i];
retryCount = 0;
// eslint-disable-next-line no-await-in-loop
await performAction(dataItem);
await performAction(dataItem, i);
if (actionInterval > 0) {
// eslint-disable-next-line no-await-in-loop
await sleepForMs(actionInterval);