From e2a679e202eb9ca693d606d31ce1ec6749fafe34 Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Thu, 23 Feb 2023 22:53:12 +0800 Subject: [PATCH] memoize status calls --- src/utils/states.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/utils/states.js b/src/utils/states.js index f3ad16e2..7bd130eb 100644 --- a/src/utils/states.js +++ b/src/utils/states.js @@ -1,3 +1,4 @@ +import mem from 'mem'; import { proxy, subscribe } from 'valtio'; import { subscribeKey } from 'valtio/utils'; @@ -130,7 +131,8 @@ export function threadifyStatus(status, propInstance) { if (!prevStatus) { if (fetchIndex++ > 3) throw 'Too many fetches for thread'; // Some people revive old threads await new Promise((r) => setTimeout(r, 500 * fetchIndex)); // Be nice to rate limits - prevStatus = await masto.v1.statuses.fetch(inReplyToId); + // prevStatus = await masto.v1.statuses.fetch(inReplyToId); + prevStatus = await fetchStatus(inReplyToId, masto); saveStatus(prevStatus, instance, { skipThreading: true }); } // Prepend so that first status in thread will be index 0 @@ -150,3 +152,7 @@ export function threadifyStatus(status, propInstance) { console.error(e, status); }); } + +const fetchStatus = mem((statusID, masto) => { + return masto.v1.statuses.fetch(statusID); +});