From 8d91bfb0a389e309af237e1c204629a12ae6350c Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Fri, 7 Jun 2024 18:38:26 +0800 Subject: [PATCH] Throttle account fetches --- src/components/status.jsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/components/status.jsx b/src/components/status.jsx index a57e057f..5efb0699 100644 --- a/src/components/status.jsx +++ b/src/components/status.jsx @@ -11,6 +11,7 @@ import { import { decodeBlurHash, getBlurHashAverageColor } from 'fast-blurhash'; import { shallowEqual } from 'fast-equals'; import prettify from 'html-prettify'; +import pThrottle from 'p-throttle'; import { Fragment } from 'preact'; import { memo } from 'preact/compat'; import { @@ -77,10 +78,14 @@ import TranslationBlock from './translation-block'; const SHOW_COMMENT_COUNT_LIMIT = 280; const INLINE_TRANSLATE_LIMIT = 140; +const throttle = pThrottle({ + limit: 1, + interval: 1000, +}); function fetchAccount(id, masto) { return masto.v1.accounts.$select(id).fetch(); } -const memFetchAccount = pmem(fetchAccount); +const memFetchAccount = pmem(throttle(fetchAccount)); const visibilityText = { public: 'Public',