Repository navigation
feat(analytics): rank nodes by neighbour count (#2100) - #2457
Conversation
868f9e5 to
85b4b58
Compare
"My node is Rank #X on its Reach page — who is #1?" New Analytics tab `neighbor-rank` lists every ranked node with its placement, name, role and all-time neighbour count, with search, role filter, paging and deep links (#/analytics?tab=neighbor-rank&q=&role=&page=&focus=). - GET /api/nodes/neighbor-rank?q=&role=&offset=&limit=&focus= (typed NeighborRankResponse). focus=<pubkey> returns the page that holds that node, so links work inside wide tie groups. - One rank view shared by the endpoint and the Reach page's Rank card, so the two always agree: ties share a placement (1, 1, 3), filters never renumber, only valid 64-hex pubkeys with a nodes row are ranked, and only edges whose both ends are valid pubkeys count. The population follows the /api/nodes visibility rule (blacklist, hidden name prefixes, geo_filter), so hidden nodes are never listed. The view is rebuilt when the degree snapshot, the visibility rules or the node cache change; the reach cache key now includes the visibility generation. - Reach card: "Not ranked" instead of "#0 / N", and a "View leaderboard" link that opens the list at the node's row. Perf: building the view for 10,000 ranked nodes 5.6 ms (once per 60 s snapshot); serving a cached page with q and role filters 0.15 ms. Inspired by dborup's Reach leaderboard (dborup#69). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
85b4b58 to
1adb680
Compare
|
I verified two cases on
|
|
Review of
Neither has a regression test yet; an E2E step for leaving the tab during the debounce and a Go case for the multi-byte query would pin both. The rest checks out. The ranking does no DB work per cached request: on 10k nodes a rebuild takes 11 ms and a cached filtered page 0.164 ms. The response types are named structs. The Smaller notes, none blocking:
Not checked: the E2E and axe suites, and a browser run. |
…eans characters Review feedback on Kpa-clawbot#2457: - The 250 ms search debounce and a request in flight both outlived the tab. The guards checked el.isConnected, but el is the shared #analyticsContent, connected on every other tab, so a late search rewrote the other tab's URL and fetched, and a late answer threw in showError. Guard on this render's own #nrRows instead, in change() and in both promise handlers. - The server's 64-character cap counted UTF-8 bytes; it now counts characters (utf8.RuneCountInString), as the docs, the error text and the input say. The client cap counts code points too, so it no longer cuts an emoji in two (which made buildQuery throw URIError). Tests: a Go case at 64/65 multi-byte characters; unit cases for the client cap; E2E step 7 leaves the tab during the debounce and with a held request, and fails on the old code on each path. Steps 3 and 7 now wait for the startup theme-refresh re-render before typing: step 3 only passed before because the replaced render's handler still ran. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Review feedback addressed (commit
Tests, each failing on
One more thing turned up. On a page load, Analytics renders the tab twice: once from Re-tested: the Not changed (the non-blocking notes): the 5 ms bench threshold, the |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Retested One small mismatch remains in the visible input. Pasting 62 ASCII letters followed by 📡 and Z gives 64 code points. The API and deep link accept all 64, but the text box drops the Z because native |
Native maxlength counts UTF-16 units, so after an emoji the box dropped characters that the API and the deep link accept (62 letters + 📡 + Z is 64 code points, 65 units). The box now has no maxlength; the input handler cuts anything past 64 code points with clampQuery, the same cut normState applies, and never leaves half a surrogate pair. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
Review feedback addressed (commit
|
Brings in Kpa-clawbot#2457, Kpa-clawbot#2490, Kpa-clawbot#2488, Kpa-clawbot#2500 and Kpa-clawbot#2455. Conflicts were two added lines on each side: the eslint globals (frameHex/frameSize and NeighborRank) and the deploy.yml E2E suite list (the privacy-on suite and test-neighbor-rank-e2e.js); both kept. The leak test now requests Kpa-clawbot#2457's /api/nodes/neighbor-rank, which serves no positions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… Pushover to Postgres Brings in 37 master commits, including the push relay (Kpa-clawbot#2447), Pushover (Kpa-clawbot#2455), plain SMTP (Kpa-clawbot#2466), neighbour rank (Kpa-clawbot#2457), the observers rebuild fix (Kpa-clawbot#2445) and Kpa-clawbot#2486. Conflicts: config.example.json, docs/api-spec.md and auth_service.go keep both sides (as n30nex's merge notes say); dbschema's observers check keeps the Postgres branch in front of Kpa-clawbot#2445's rowid-alias check; the release-routing test keeps musl-test; CHANGELOG keeps only unreleased entries; notify_service.go keeps master's destinations plus the cluster lock on evaluation, and the email claim moves to notifyChanges.claim. users.db schema: master's v11 (push relay) and v12 (Pushover) come first, this branch's rate_limits becomes v13, and v14 adds push_relay_state, push_relay_pending and notification_pushover_subscriptions. Push relay and Pushover on Postgres with several server replicas: - Postgres migrations v11-v14 with the five SQLite triggers as plpgsql; instr -> strpos, typed VALUES, a qualified ON CONFLICT WHERE, integer booleans. The parity test also compares trigger names. - Relay enrollment, delivery phase and the pending enrollment (with the Ed25519 proof seed) move from <users.db>.push-relay*.json and process memory into the accounts store. Writes are compare-and-set on a revision; replicas reload it per tick, per dispatch pass and per job. Old files are imported once, except an enrollment under a manual relay or for another public origin, which is left on disk and never prunes. - Credentials and the seed are sealed with userManagement.encryptionKey (CORESCOPE_ACCOUNTS_KEY), required on Postgres; on SQLite without a key they are stored as before, inside users.db. Leftover plain values are re-sealed at startup once a key is set. users.db is set to 0600, and user backups blank the relay secrets. - Queue rows are claimed with a 5-minute lease (SKIP LOCKED on Postgres); each queue drains under a cluster lock; advisory locks use their own connection pool, so lock holders cannot starve the accounts store. Device links and the Pushover per-user limit lock the user. - The enrollment proof and the Pushover connect token work on any replica; the proof endpoint validates before any database read and is limited per IP; device link/unlink are limited per user. Also fixed while integrating: - node_reach used IS NOT 'tx', which Postgres rejects (from Kpa-clawbot#2486). - docker/server-exec.sh did not pass five variables the server reads (CORESCOPE_ACCOUNTS_KEY, CORESCOPE_PUSHOVER_TOKEN, CORESCOPE_PUSH_RELAY_CREDENTIAL, CORESCOPE_SMTP_PASSWORD, CORESCOPE_URL); tests/unit/test-server-exec-env.js now checks the list. - corescope-migrate copy-users/verify-users failed on notification_pushover_sent (no key); it gets a rowid on Postgres, like mail_events, and verify redacts credential and seed columns. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Summary
Answers #2100: "My node is Rank #X on its Reach page — who is #1?"
A new Neighbor Rank tab on the Analytics page lists every ranked node by all-time neighbour count. Each row shows the node's placement, name, role and neighbour count, with a link to its Reach page. The tab has search, a role filter, paging and deep links. The Reach page's Rank card now links to it and opens the list at the node's own row.
Inspired by dborup's Reach leaderboard in their fork (dborup#69). This is a fresh implementation on current master.
What changed
GET /api/nodes/neighbor-rank?q=&role=&offset=&limit=&focus=returns a typedNeighborRankResponse:entries,total,offset,ranked,snapshot_at.focus=<pubkey>returns the page that contains that node, so a link to a node deep inside a large tie group still lands on its row.node_a, which used to show up as a nameless Feed panel overflow:hidden silently clips items instead of scrolling #1./api/nodesrule (blacklist, hidden name prefixes, geo_filter), so hidden nodes are never listed. The view is rebuilt when the degree snapshot, the visibility rules or the node cache change. The reach cache key now includes the visibility generation.#0 / N, plus a View leaderboard link.public/neighbor-rank.jswith pure helpers, unit-tested viavm. Search is debounced, only the tbody is replaced, and stale responses are dropped. A debounced search or a response that arrives after the user leaves the tab does nothing (it checks the tab's own rows, not the shared#analyticsContent). The tab has loading, empty, no-match and error-with-Retry states. All colours are CSS variables (--link-color,--accent-strong). It fits a 360 px phone without sideways scrolling.Performance
qandrolefiltersTestNeighborRankCachedPageUnder5msFor10kNodesasserts the serve time.Tests
qlimit counts characters, not bytes (multi-byte cases at 64 and 65), ties, degree-0 nodes, hidden and blacklisted nodes excluded from both the list and the card, card == list, filters don't renumber, paging, every bad parameter returns 400, 503 without a snapshot, invalid and empty pubkeys, a node without a row excluded, a rename into a hidden prefix, a stale-view race, andfocusacross a 130-node tie group.tests/unit/test-neighbor-rank.js(21 tests), including the client's 64-character cap on accented text and emoji, in the URL state and in the search box (code points, not UTF-16 units).tests/e2e/test-neighbor-rank-e2e.js, added todeploy.yml(shard 1). Step 7 leaves the tab during the debounce and with a held request; it fails on the code before5e372f47. Step 4b pastes 62 letters, 📡 and Z (64 code points) and checks the box keeps all of them and cuts a 65th. The tab is added to the axe suite (108 cells, 0 violations).Local runs:
cmd/serversuite, plus-raceon the new teststest-all.shtest-issue-1147.Notes for reviewers
Review fixes are in
5e372f47; see the reply comment.The Reach card's rank and total change slightly on instances that hide nodes, because hidden nodes are no longer counted. This is intentional, so the card and the list agree.
The Reach response is cached for 5 minutes, so the number on the card can trail the list by up to that long. The leaderboard link still lands on the right row, because the server resolves it with
focus.Paging and filters update the URL with
replaceState, like the other Analytics tabs. Back does not step through pages.If feat(db): PostgreSQL as an alternative database backend #2396 (Postgres) merges first, its parity test
pg_store_queries_test.gomust stop readingdegreeSnapshot.total/sortedDesc, which this PR removed as dead. That's a one-line change, already done on our integration branch.Merging with the other overnight PR: whichever lands second needs a one-line rebase in
.github/workflows/deploy.yml(both add a suite line next to test-node-reach-e2e.js).🤖 Generated with Claude Code