From 9f31cc8e07cd4d8dace045692ab0f25bd236468b Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Sat, 4 Nov 2023 19:18:12 +0800 Subject: [PATCH] Some sort of "garbage collection" --- src/app.jsx | 23 +++++++++++++++++++++++ src/components/media-post.jsx | 1 + src/components/status.jsx | 1 + 3 files changed, 25 insertions(+) diff --git a/src/app.jsx b/src/app.jsx index b30b9fba..09affaa1 100644 --- a/src/app.jsx +++ b/src/app.jsx @@ -68,8 +68,31 @@ window.__STATES_STATS__ = () => { counts[key] = Object.keys(states[key]).length; }); console.warn('STATE stats', counts); + + const { statuses } = states; + const unmountedPosts = []; + for (const key in statuses) { + const $post = document.querySelector(`[data-state-post-id="${key}"]`); + if (!$post) { + unmountedPosts.push(key); + } + } + console.warn('Unmounted posts', unmountedPosts.length, unmountedPosts); }; +// Experimental "garbage collection" for states +// Every 5 minutes +// Only posts for now +setInterval(() => { + const { statuses } = states; + for (const key in statuses) { + const $post = document.querySelector(`[data-state-post-id="${key}"]`); + if (!$post) { + delete states.statuses[key]; + } + } +}, 5 * 60 * 1000); + // Preload icons // There's probably a better way to do this // Related: https://github.com/vitejs/vite/issues/10600 diff --git a/src/components/media-post.jsx b/src/components/media-post.jsx index 6a5a30aa..fdc1040c 100644 --- a/src/components/media-post.jsx +++ b/src/components/media-post.jsx @@ -116,6 +116,7 @@ function MediaPost({ const filterTitleStr = filterInfo?.titlesStr; return ( { statusRef.current = node; // Use parent node if it's in focus