this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Further rate limit this threadify calls

Every post calls threadify and clogs the RAF

+30 -2
+26
src/utils/ratelimit.js
··· 1 + // Rate limit repeated function calls and queue them to set interval 2 + export default function rateLimit(fn, interval) { 3 + let queue = []; 4 + let isRunning = false; 5 + 6 + function executeNext() { 7 + if (queue.length === 0) { 8 + isRunning = false; 9 + return; 10 + } 11 + 12 + const nextFn = queue.shift(); 13 + nextFn(); 14 + setTimeout(executeNext, interval); 15 + } 16 + 17 + return function (...args) { 18 + const callFn = () => fn.apply(this, args); 19 + queue.push(callFn); 20 + 21 + if (!isRunning) { 22 + isRunning = true; 23 + setTimeout(executeNext, interval); 24 + } 25 + }; 26 + }
+4 -2
src/utils/states.js
··· 3 3 4 4 import { api } from './api'; 5 5 import pmem from './pmem'; 6 + import rateLimit from './ratelimit'; 6 7 import store from './store'; 7 8 8 9 const states = proxy({ ··· 187 188 } 188 189 } 189 190 190 - export function threadifyStatus(status, propInstance) { 191 + function _threadifyStatus(status, propInstance) { 191 192 const { masto, instance } = api({ instance: propInstance }); 192 193 // Return all statuses in the thread, via inReplyToId, if inReplyToAccountId === account.id 193 194 let fetchIndex = 0; ··· 204 205 let prevStatus = states.statuses[key]; 205 206 if (!prevStatus) { 206 207 if (fetchIndex++ > 3) throw 'Too many fetches for thread'; // Some people revive old threads 207 - await new Promise((r) => setTimeout(r, 500 * fetchIndex)); // Be nice to rate limits 208 + await new Promise((r) => setTimeout(r, 300 * fetchIndex)); // Be nice to rate limits 208 209 // prevStatus = await masto.v1.statuses.$.select(inReplyToId).fetch(); 209 210 prevStatus = await fetchStatus(inReplyToId, masto); 210 211 saveStatus(prevStatus, instance, { skipThreading: true }); ··· 226 227 console.error(e, status); 227 228 }); 228 229 } 230 + export const threadifyStatus = rateLimit(_threadifyStatus, 300); 229 231 230 232 const fetchStatus = pmem((statusID, masto) => { 231 233 return masto.v1.statuses.$select(statusID).fetch();