mirror of
https://github.com/PR0M3TH3AN/Artstr-Studio.git
synced 2026-11-05 13:10:39 +00:00
Community browser: don't trash the welcome modal's pre-warmed cache
The previous "auto-refresh on Browse click" commit unconditionally called invalidateFeedCache() before opening the modal. That set _feedCache.events = null and forced a 6-second re-fetch on every Browse click — wiping the cache the welcome modal had populated seconds earlier. Symptom: cold reload → welcome loads instantly → exit → Browse shows "Loading..." for ~6s with nothing rendered, while changing the type filter (which only re-filters the cache) appears to "work" once the fetch finally lands. Smarter behaviour: - Add a `force` option to fetchFeedAndReactions that bypasses its 5-minute cache check. Use this from the Browse buttons. - Don't blow away the cache. Open the modal, switch to the New tab, which renders cached cards immediately via the existing `if (_feedCache.events && _feedCache.events.length) rerender()` path in loadFeedTab. Then trigger a force refresh only if the cache is staleish (>30s old). So: welcome just-loaded cache (age=2-5s) → Browse opens instantly with those cards, no extra fetch. Older cache (age=1m, 4m, etc.) → Browse renders cached cards instantly AND kicks off a background refresh whose progress streams in via notifyFeedProgress. The explicit Refresh button in the modal is still available for on-demand forced pulls. Co-Authored-By: Claude Opus 4.7 <[email protected]>
This commit is contained in:
1 parent
e8c3115236
commit
d6dcdfba11
1 file changed
+17
-7
+17
-7
@@ -16302,12 +16302,16 @@
|
||||
_zapCache.fetchedForAuthors.clear();
|
||||
}
|
||||
|
||||
async function fetchFeedAndReactions() {
|
||||
async function fetchFeedAndReactions(opts) {
|
||||
const relays = splitRelayList(state.community.relays);
|
||||
const relayKey = relays.join(',');
|
||||
const age = Date.now() - _feedCache.fetchedAt;
|
||||
if (_feedCache.loading) return;
|
||||
if (_feedCache.events && age < 5 * 60 * 1000 && _feedCache.relayKey === relayKey) return;
|
||||
// `force: true` bypasses the 5-minute cache. Used by the Browse button
|
||||
// to refresh in the background while the existing cached cards stay
|
||||
// on screen, so the user sees content immediately.
|
||||
const force = !!(opts && opts.force);
|
||||
if (!force && _feedCache.events && age < 5 * 60 * 1000 && _feedCache.relayKey === relayKey) return;
|
||||
_feedCache.loading = true;
|
||||
_feedCache.relayKey = relayKey;
|
||||
_feedCache.reactions = {};
|
||||
@@ -22061,12 +22065,17 @@
|
||||
btn.classList.toggle('active', btn.dataset.type === 'any');
|
||||
});
|
||||
}
|
||||
// Auto-refresh on open. fetchFeedAndReactions otherwise honours a
|
||||
// 5-minute cache and the user would see stale results (including
|
||||
// their own design they just published).
|
||||
invalidateFeedCache();
|
||||
$('nostrModal').classList.add('open');
|
||||
switchModalTab('New');
|
||||
// The welcome modal pre-warms `_feedCache.events` on cold load, so
|
||||
// opening Browse should hit that cache and render cards instantly.
|
||||
// Only trigger a forced refresh if the cache is genuinely staleish
|
||||
// (>30s old) — otherwise the welcome's just-loaded data gets
|
||||
// wiped by fetchFeedAndReactions clearing reactions/profiles
|
||||
// mid-fetch. Use the explicit Refresh button in the modal for an
|
||||
// on-demand fresh pull.
|
||||
const cacheAge = Date.now() - (_feedCache.fetchedAt || 0);
|
||||
if (cacheAge > 30000) fetchFeedAndReactions({ force: true });
|
||||
});
|
||||
$('designerBrowseCommunityBtn').addEventListener('click', () => {
|
||||
for (const t of ['New', 'Popular', 'Mine']) {
|
||||
@@ -22076,9 +22085,10 @@
|
||||
btn.classList.toggle('active', btn.dataset.type === 'disc-design');
|
||||
});
|
||||
}
|
||||
invalidateFeedCache();
|
||||
$('nostrModal').classList.add('open');
|
||||
switchModalTab('New');
|
||||
const cacheAge = Date.now() - (_feedCache.fetchedAt || 0);
|
||||
if (cacheAge > 30000) fetchFeedAndReactions({ force: true });
|
||||
});
|
||||
$('welcomeSearchBtn').addEventListener('click', runWelcomeSearch);
|
||||
$('welcomeSkipBtn').addEventListener('click', dismissWelcomeModal);
|
||||
|
||||
Reference in new issue
Block a user