Fix too many requests caused by relationship look-ups in web UI (#32042)

Co-authored-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
Eugen RochkoandClaire authored and GitHub committed 2024-09-24 17:02:36 +00:00
1 parent f1b6a611aa
commit 70988519df
3 files changed
+40 -19

No files matched your search

+23
View File
@@ -0,0 +1,23 @@
import { debounce } from 'lodash';
import type { AppDispatch } from 'mastodon/store';
export const debounceWithDispatchAndArguments = <T>(
fn: (dispatch: AppDispatch, ...args: T[]) => void,
{ delay = 100 },
) => {
let argumentBuffer: T[] = [];
let dispatchBuffer: AppDispatch;
const wrapped = debounce(() => {
const tmpBuffer = argumentBuffer;
argumentBuffer = [];
fn(dispatchBuffer, ...tmpBuffer);
}, delay);
return (dispatch: AppDispatch, ...args: T[]) => {
dispatchBuffer = dispatch;
argumentBuffer.push(...args);
wrapped();
};
};