Skip to content

Refactor ENSApi: inject SWR Cache objects with DI context#2337

Merged
tk-o merged 9 commits into
mainfrom
refactor/2029-inject-swr-caches-with-di-context
Jul 7, 2026
Merged

Refactor ENSApi: inject SWR Cache objects with DI context#2337
tk-o merged 9 commits into
mainfrom
refactor/2029-inject-swr-caches-with-di-context

Conversation

@tk-o

@tk-o tk-o commented Jun 29, 2026

Copy link
Copy Markdown
Member

Lite PR

Tip: Review docs on the ENSNode PR process

Summary

  • Refactored ENSApi's SWR Cache objects (indexingStatusCache, stackInfoCache, referralProgramEditionConfigSetCache) from lazy-initialized module-level singletons created with lazyProxy helper into builder functions that receive dependencies explicitly.
  • Injected the SWR Caches through the existing DI context so construction is deferred until first access, without relying on lazy/lazyProxy.
    • Updated config.singleton.test.ts to mock the new builder functions.
  • Removed the now-unused lazy.ts utility.

Why

  • Creating SWR Cache objects required applying lazyProxy function to defer object initialization.
  • Module-level lazy singletons required async 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

  • Updated apps/ensapi/src/config/config.singleton.test.ts to mock the new build* cache functions.
  • Ran pnpm test --project ensapi and pnpm -F ensapi typecheck locally.
  • Performed smoke tests while running a local ENSApi instance.

Notes for Reviewer (Optional)

  • Related to Apply dependency injection container for ENSApi #2029
  • Feel free to review commit by commit, with the "hide whitespaces" setting ON
  • No external API or behaviour changes are expected; this is a pure internal refactor of ENSApi's DI wiring.
  • No changeset is included because ENSApi is a private deployed app and this change does not affect any published npm package surface.

Pre-Review Checklist (Blocking)

  • This PR does not introduce significant changes and is low-risk to review quickly.
  • Relevant changesets are included (or are not required)

Copilot AI review requested due to automatic review settings June 29, 2026 11:15
@changeset-bot

changeset-bot Bot commented Jun 29, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: bd7d966

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel

vercel Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
enskit-react-example.ensnode.io Ready Ready Preview, Comment Jul 7, 2026 11:24am
3 Skipped Deployments
Project Deployment Actions Updated (UTC)
admin.ensnode.io Skipped Skipped Jul 7, 2026 11:24am
ensnode.io Skipped Skipped Jul 7, 2026 11:24am
ensrainbow.io Skipped Skipped Jul 7, 2026 11:24am

@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@tk-o, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 55 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

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 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 configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 2c7b134a-73e2-4917-8768-16e821046eb9

📥 Commits

Reviewing files that changed from the base of the PR and between ac07f68 and bd7d966.

📒 Files selected for processing (11)
  • apps/ensapi/src/cache/indexing-status.cache.ts
  • apps/ensapi/src/cache/referral-edition-snapshots.cache.ts
  • apps/ensapi/src/cache/referral-program-edition-set.cache.ts
  • apps/ensapi/src/cache/stack-info.cache.ts
  • apps/ensapi/src/config/config.singleton.test.ts
  • apps/ensapi/src/di.ts
  • apps/ensapi/src/lib/lazy.ts
  • apps/ensapi/src/middleware/indexing-status.middleware.ts
  • apps/ensapi/src/middleware/referral-program-edition-set.middleware.ts
  • apps/ensapi/src/middleware/stack-info.middleware.ts
  • apps/ensapi/src/omnigraph-api/lib/find-domains/find-domains-resolver-helpers.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/2029-inject-swr-caches-with-di-context

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.

❤️ Share

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

@tk-o

tk-o commented Jun 29, 2026

Copy link
Copy Markdown
Member Author

@greptile review

@greptile-apps

greptile-apps Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR refactors ENSApi cache construction into the DI context. The main changes are:

  • Replaces lazy cache singletons with explicit cache builder functions.
  • Wires indexing status, stack info, and referral edition caches through di.context.
  • Updates middleware to read caches from the DI container.
  • Updates tests to mock the new cache builders.
  • Removes the unused lazy utility.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.

Important Files Changed

Filename Overview
apps/ensapi/src/di.ts Adds DI-owned construction for the refactored SWR cache builders.
apps/ensapi/src/cache/indexing-status.cache.ts Converts the indexing status cache into a builder that receives the ENSDb reader.
apps/ensapi/src/cache/stack-info.cache.ts Converts the stack info cache into a builder that receives ENSDb and API config dependencies.
apps/ensapi/src/cache/referral-program-edition-set.cache.ts Converts the referral edition config cache into a builder that receives the configured URL.
apps/ensapi/src/middleware/indexing-status.middleware.ts Resolves the indexing status cache from the DI context during middleware execution.
apps/ensapi/src/middleware/referral-program-edition-set.middleware.ts Resolves the referral edition config cache from the DI context during middleware execution.
apps/ensapi/src/middleware/stack-info.middleware.ts Resolves the stack info cache from the DI context during middleware execution.

Reviews (2): Last reviewed commit: "Apply AI PR feedback" | Re-trigger Greptile

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 without lazyProxy).
  • Removed the unused apps/ensapi/src/lib/lazy.ts utility 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.

Comment thread apps/ensapi/src/cache/stack-info.cache.ts Outdated
Comment thread apps/ensapi/src/cache/referral-program-edition-set.cache.ts
Copilot AI review requested due to automatic review settings July 7, 2026 11:24
@vercel vercel Bot temporarily deployed to Preview – ensnode.io July 7, 2026 11:24 Inactive
@vercel vercel Bot temporarily deployed to Preview – ensrainbow.io July 7, 2026 11:24 Inactive
@vercel vercel Bot temporarily deployed to Preview – admin.ensnode.io July 7, 2026 11:24 Inactive
@tk-o tk-o marked this pull request as ready for review July 7, 2026 11:26
@tk-o tk-o requested a review from a team as a code owner July 7, 2026 11:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated no new comments.

@tk-o tk-o linked an issue Jul 7, 2026 that may be closed by this pull request
@tk-o tk-o merged commit 8ba02d5 into main Jul 7, 2026
24 checks passed
@tk-o tk-o deleted the refactor/2029-inject-swr-caches-with-di-context branch July 7, 2026 18:34
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.

Apply dependency injection container for ENSApi

3 participants