Garbage collect status quotes & unfurled links too

Make this less destructive by setting to 15min interval
Ignore whatever errors inside
This commit is contained in:
Lim Chee Aun 2023-11-05 10:12:52 +08:00
parent 986187141e
commit b461823d60

View file

@ -49,7 +49,7 @@ import {
} from './utils/api'; } from './utils/api';
import { getAccessToken } from './utils/auth'; import { getAccessToken } from './utils/auth';
import focusDeck from './utils/focus-deck'; import focusDeck from './utils/focus-deck';
import states, { initStates } from './utils/states'; import states, { initStates, statusKey } from './utils/states';
import store from './utils/store'; import store from './utils/store';
import { getCurrentAccount } from './utils/store-utils'; import { getCurrentAccount } from './utils/store-utils';
import './utils/toast-alert'; import './utils/toast-alert';
@ -81,18 +81,29 @@ window.__STATES_STATS__ = () => {
}; };
// Experimental "garbage collection" for states // Experimental "garbage collection" for states
// Every 5 minutes // Every 15 minutes
// Only posts for now // Only posts for now
setInterval(() => { setInterval(() => {
if (!window.__IDLE__) return; if (!window.__IDLE__) return;
const { statuses } = states; const { statuses, unfurledLinks } = states;
for (const key in statuses) { for (const key in statuses) {
const $post = document.querySelector(`[data-state-post-id~="${key}"]`); try {
if (!$post) { const $post = document.querySelector(`[data-state-post-id~="${key}"]`);
delete states.statuses[key]; if (!$post) {
} delete states.statuses[key];
delete states.statusQuotes[key];
for (const link in unfurledLinks) {
const unfurled = unfurledLinks[link];
const sKey = statusKey(unfurled.id, unfurled.instance);
if (sKey === key) {
delete states.unfurledLinks[link];
break;
}
}
}
} catch (e) {}
} }
}, 5 * 60 * 1000); }, 15 * 60 * 1000);
// Preload icons // Preload icons
// There's probably a better way to do this // There's probably a better way to do this