From c82e042aa592e4e619d0c280b02486eeb859d358 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Wed, 7 Oct 2026 13:10:43 -0700 Subject: Profile links paint whole on the first frame: the server renders /npub1…, /nprofile1… and / with the kind 0, latest posts, follow counts and mentioned faces inlined (stale-while-refresh cache, 2 s budget), the app seeds its caches from it, and the big avatar never flashes punk art while a lookup runs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A cold visit to a profile link showed a punk, '–' counts and no posts for 9 s. Server-side relay answers settle once events stop arriving (idle 400 ms) instead of waiting out a relay that never sends EOSE: a cold build is ~1.9 s. Co-Authored-By: Claude Opus 5.5 --- feed/server.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'feed/server.js') diff --git a/feed/server.js b/feed/server.js index 12ff850..9566447 100644 --- a/feed/server.js +++ b/feed/server.js @@ -2,26 +2,34 @@ import { SimplePool } from 'nostr-tools/pool'; import { startFeedCache } from './service.js'; import { snapshotResponse } from './cache.js'; import { NOTE_PATH, buildThread, createThreadCache, createIndexSource, notePageResponse } from './note-page.js'; +import { PROFILE_PATH, buildProfile, createPrimal, createNameResolver, profilePageResponse } from './profile-page.js'; const cache = await startFeedCache(); // SimplePool verifies signatures and matches filters before accepting events. const pool = new SimplePool(); // Every relay's answer, or maxWait — but an ask by id is done the moment -// every id has turned up, rather than waiting out the slowest relay. -const query = (relays, filter, maxWait) => new Promise((resolve) => { +// every id has turned up, rather than waiting out the slowest relay. With +// `idle`, the answer is also done once events have been arriving and then +// stop for that long: one relay that never says EOSE no longer holds a +// profile page for the whole maxWait. +const query = (relays, filter, maxWait, { idle = 0 } = {}) => new Promise((resolve) => { const got = new Map(); - let done = false, sub = null; - const finish = () => { if (done) return; done = true; try { sub && sub.close(); } catch {} resolve([...got.values()]); }; + let done = false, sub = null, quiet = null; + const finish = () => { if (done) return; done = true; clearTimeout(quiet); try { sub && sub.close(); } catch {} resolve([...got.values()]); }; sub = pool.subscribeManyEose(relays, filter, { maxWait, onevent(e) { got.set(e.id, e); if (filter.ids && filter.ids.every((id) => got.has(id))) finish(); + if (idle) { clearTimeout(quiet); quiet = setTimeout(finish, idle); } }, onclose: finish, }); if (done) try { sub.close(); } catch {} }); const threads = createThreadCache({ build: (ref) => buildThread(ref, query) }); +const primal = createPrimal(); +const profiles = createThreadCache({ build: (ref) => buildProfile(ref, { query, primal }) }); +const resolveName = createNameResolver({ url: process.env.NAMES_URL || 'https://names.coinos.io' }); const index = createIndexSource(process.env.INDEX_URL || 'http://bitcoin-wallet/index.html'); const server = Bun.serve({ hostname: process.env.HOST || '127.0.0.1', @@ -33,6 +41,9 @@ const server = Bun.serve({ if (NOTE_PATH.test(path) && ['GET', 'HEAD'].includes(req.method)) { try { return await notePageResponse(req, { index, threads }); } catch { return new Response('Unavailable', { status: 502 }); } } + if (PROFILE_PATH.test(path) && ['GET', 'HEAD'].includes(req.method)) { + try { return await profilePageResponse(req, { index, profiles, resolveName }); } catch { return new Response('Unavailable', { status: 502 }); } + } return new Response('Not found', { status: 404 }); }, }); -- cgit v1.2.3