Skip to content

perf: cache plan-nodes query (provider-scoped, 15s TTL) to fix add-nodes delay#14

Open
Sentinel-Bluebuilder wants to merge 1 commit into
masterfrom
feat/server-plan-nodes-caching
Open

perf: cache plan-nodes query (provider-scoped, 15s TTL) to fix add-nodes delay#14
Sentinel-Bluebuilder wants to merge 1 commit into
masterfrom
feat/server-plan-nodes-caching

Conversation

@Sentinel-Bluebuilder

Copy link
Copy Markdown
Owner

What

Caches the expensive getNodesForPlan query and invalidates it on link/unlink.

Why

getNodesForPlan performs an RPC QueryNodesForPlan plus a per-member
rpcQueryLeasesForNode fan-out. It was being re-run on every Add-Nodes
keystroke, every filter change, and every post-link refetch — the root cause of
the "big delay before added nodes show" symptom operators reported.

How

  • Renamed the existing implementation to _getNodesForPlanImpl(planId).
  • New getNodesForPlan(planId) wraps it in cached() with a 15s TTL, keyed
    by planNodes:<planId>:<provider>. The key is provider-scoped because the
    per-node lease lookup selects our lease (prov_address === getProvAddr()),
    so results are provider-specific and must not be shared across operators.
  • New invalidatePlanNodes(planId) does an exact-key cacheInvalidate.
  • The four mutating routes — link, batch-link, unlink, batch-unlink
    call invalidatePlanNodes(planIdNum) right after the ownership gate, so a
    just-added/removed node is reflected on the very next refetch (subject to chain
    indexing latency).

Notes

  • RPC-first preserved (getRpcClient() path unchanged inside the impl).
  • cached / cacheInvalidate are already imported from blue-js-sdk; the SDK's
    cacheInvalidate(key) is an exact-key delete (no prefix match), which is why
    invalidation reconstructs the same planNodes:<id>:<prov> key.
  • Scoped to server.js only; no behavior change when the cache misses.

🤖 Generated with Claude Code

getNodesForPlan does an RPC QueryNodesForPlan plus a per-member
rpcQueryLeasesForNode fan-out. It was re-run on every Add-Nodes
keystroke, filter, and post-link refetch, which was the root of the
"big delay before added nodes show" symptom.

Wrap it in cached() keyed by planId + provider (the per-node lease
lookup selects OUR lease via prov_address === getProvAddr(), so the
result is provider-specific). Short 15s TTL keeps it fresh.

Link/unlink/batch-link/batch-unlink success paths call
invalidatePlanNodes(planId) so a just-added or just-removed node is
reflected on the very next refetch (subject to chain indexing).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant