Skip to content

feat(backend): cache listServices to reduce RPC simulation calls#195

Open
leocagli wants to merge 1 commit into
Stellar-Ecosystem:mainfrom
leocagli:feat/list-services-cache
Open

feat(backend): cache listServices to reduce RPC simulation calls#195
leocagli wants to merge 1 commit into
Stellar-Ecosystem:mainfrom
leocagli:feat/list-services-cache

Conversation

@leocagli

Copy link
Copy Markdown
Contributor

Closes #6

Summary

Every call to GET /api/services triggered a Soroban simulation call to list_services_page — one per page, per request. With concurrent users or the frontend's 30s auto-refresh, this creates unnecessary load on the RPC node.

  • Added a per-key in-memory cache in contract.js keyed on category:page:pageSize
  • TTL = 30s (aligned with the frontend SWR refreshInterval)
  • invalidateServicesCache() is called automatically inside registerServiceOnChain() so newly-registered services appear immediately without waiting for TTL expiry
  • Cache is module-level (process-scoped) — survives across requests, resets on process restart

Test plan

  • First request populates cache; second identical request within 30s returns cached data (no RPC call)
  • After 30s the cache entry expires and the next request fetches fresh data
  • After registerServiceOnChain(), the next GET /api/services shows the new service (cache was invalidated)
  • Different category/page/pageSize combinations each get their own cache entry

…calls

Closes Stellar-Ecosystem#6

Every paginated request to GET /api/services was invoking a full Soroban
simulation call to list_services_page — expensive with many concurrent
users or rapid polling.

Changes:
- Added per-key in-memory cache in contract.js keyed on category:page:pageSize
- Cache TTL = 30s (matches the frontend's SWR refreshInterval)
- Cache is invalidated on registerServiceOnChain() so newly-registered
  services appear on the next request without waiting for TTL expiry
- Exported invalidateServicesCache() for routes that mutate service state
@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@leocagli, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 1 second. Learn how PR review limits work.

To continue reviewing without waiting, enable usage-based billing in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 60952211-9ffe-43b6-aed2-a02d8b98eef6

📥 Commits

Reviewing files that changed from the base of the PR and between 6fb6da9 and f0124c3.

📒 Files selected for processing (1)
  • backend/src/lib/contract.js
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant