Some sort of "garbage collection"

This commit is contained in:
Lim Chee Aun 2023-11-04 19:18:12 +08:00
parent 660cbebbc4
commit 9f31cc8e07
3 changed files with 25 additions and 0 deletions

View file

@ -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

View file

@ -116,6 +116,7 @@ function MediaPost({
const filterTitleStr = filterInfo?.titlesStr;
return (
<Parent
data-state-post-id={sKey}
onMouseEnter={debugHover}
key={mediaKey}
data-spoiler-text={

View file

@ -973,6 +973,7 @@ function Status({
return (
<article
data-state-post-id={sKey}
ref={(node) => {
statusRef.current = node;
// Use parent node if it's in focus