mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-09-13 22:32:26 +03:00
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:
parent
83057ebbd4
commit
a23279e633
4 changed files with 270 additions and 187 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue