Custom Emoji: Fix loading large quantities (#2820)

This commit is contained in:
Alexander Zinchuk 2023-03-19 22:31:13 -05:00
parent 2d2ac41c6b
commit 487cde9176

View File

@ -5,16 +5,27 @@ import { throttle } from '../util/schedulers';
import useLastSyncTime from './useLastSyncTime';
const LOAD_QUEUE = new Set<string>();
let LOAD_QUEUE = new Set<string>();
const RENDER_HISTORY = new Set<string>();
const THROTTLE = 200;
const LIMIT_PER_REQUEST = 100;
const loadFromQueue = throttle(() => {
const queue = [...LOAD_QUEUE];
const queueToLoad = queue.slice(0, LIMIT_PER_REQUEST);
const otherQueue = queue.slice(LIMIT_PER_REQUEST + 1);
getActions().loadCustomEmojis({
ids: [...LOAD_QUEUE],
ids: queueToLoad,
});
LOAD_QUEUE.clear();
LOAD_QUEUE = new Set(otherQueue);
// Schedule next load
if (LOAD_QUEUE.size) {
loadFromQueue();
}
}, THROTTLE, false);
const updateLastRendered = throttle(() => {