Refactor ENSApi: inject SWR Cache objects with DI context#2337
Conversation
This builder function will allow to defer the cache initialization.
This builder function will allow to defer the cache initialization.
… Cache This builder function will allow to defer the cache initialization.
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
3 Skipped Deployments
|
|
Warning Review limit reached
Next review available in: 55 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the 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 reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. 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, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (11)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@greptile review |
Greptile SummaryThis PR refactors ENSApi cache construction into the DI context. The main changes are:
Confidence Score: 5/5This looks safe to merge.
Important Files Changed
Reviews (2): Last reviewed commit: "Apply AI PR feedback" | Re-trigger Greptile |
There was a problem hiding this comment.
Pull request overview
Refactors ENSApi’s SWR cache construction to be dependency-injected via the existing DI container, removing module-level lazy singletons and eliminating the lazyProxy/lazy utility to simplify dependency graphs and testing.
Changes:
- Converted SWR cache modules from exported lazy singletons to
build*Cache(...)factory functions that take explicit dependencies. - Updated DI container and middlewares to retrieve caches from
di.context(deferred construction withoutlazyProxy). - Removed the unused
apps/ensapi/src/lib/lazy.tsutility and updated the DI bootstrap test mocks accordingly.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| apps/ensapi/src/omnigraph-api/lib/find-domains/find-domains-resolver-helpers.ts | Removes outdated lazy-proxy rationale; uses DI context access path. |
| apps/ensapi/src/middleware/stack-info.middleware.ts | Reads stackInfoCache from di.context instead of importing a singleton. |
| apps/ensapi/src/middleware/referral-program-edition-set.middleware.ts | Reads referralProgramEditionConfigSetCache from di.context. |
| apps/ensapi/src/middleware/indexing-status.middleware.ts | Reads indexingStatusCache from di.context. |
| apps/ensapi/src/lib/lazy.ts | Deletes lazy/lazyProxy utilities (no longer used). |
| apps/ensapi/src/di.ts | Updates DI context getters to construct caches via build*Cache(...) factories. |
| apps/ensapi/src/config/config.singleton.test.ts | Updates mocks to mock cache builder functions instead of singleton exports. |
| apps/ensapi/src/cache/stack-info.cache.ts | Replaces lazy singleton export with buildStackInfoCache(ensDbClient, ensApiConfig). |
| apps/ensapi/src/cache/referral-program-edition-set.cache.ts | Replaces lazy singleton export with buildReferralProgramEditionConfigSetCache(url). |
| apps/ensapi/src/cache/referral-edition-snapshots.cache.ts | Switches indexing status cache access to DI context. |
| apps/ensapi/src/cache/indexing-status.cache.ts | Replaces lazy singleton export with buildIndexingStatusCache(ensDbClient). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…swr-caches-with-di-context
Lite PR
Tip: Review docs on the ENSNode PR process
Summary
indexingStatusCache,stackInfoCache,referralProgramEditionConfigSetCache) from lazy-initialized module-level singletons created withlazyProxyhelper into builder functions that receive dependencies explicitly.lazy/lazyProxy.config.singleton.test.tsto mock the new builder functions.lazy.tsutility.Why
lazyProxyfunction to defer object initialization.import("@/di")inside cache loaders to avoid circular dependencies, coupling the cache modules to the DI container. Passing dependencies explicitly through DI context getters removes that coupling and makes the cache modules simpler to test and reason about.Testing
apps/ensapi/src/config/config.singleton.test.tsto mock the newbuild*cache functions.pnpm test --project ensapiandpnpm -F ensapi typechecklocally.Notes for Reviewer (Optional)
Pre-Review Checklist (Blocking)