Skip to content

fix(affiliate): dune caching & error repoting & linting#216

Merged
kernelwhisperer merged 3 commits intomainfrom
feat/affiliate-trader-activity
May 5, 2026
Merged

fix(affiliate): dune caching & error repoting & linting#216
kernelwhisperer merged 3 commits intomainfrom
feat/affiliate-trader-activity

Conversation

@kernelwhisperer
Copy link
Copy Markdown
Contributor

@kernelwhisperer kernelwhisperer commented Apr 29, 2026

Please ignore the branch name.

Summary

image

@kernelwhisperer kernelwhisperer changed the title Feat/affiliate trader activity feat(affiliate): trader activity table Apr 29, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 29, 2026

📝 Walkthrough

Walkthrough

The changes add a comprehensive Jest test suite for the Inversify container factory, export the getApiContainer function for external access, update AffiliateStatsService to use singleton scope ensuring a single shared instance, reduce the affiliate stats cache TTL from 1 hour to 5 minutes, and modify error logging in two route handlers to use structured logging format.

Changes

Cohort / File(s) Summary
Inversify Container Configuration
apps/api/src/app/inversify.config.ts
Exports getApiContainer function, applies inSingletonScope() to AffiliateStatsService binding for single instance reuse, and reduces cache TTL default from 1 hour to 5 minutes.
Inversify Container Tests
apps/api/src/app/inversify.config.spec.ts
New comprehensive test suite for getApiContainer with mocked repositories and services, verifies singleton scope behavior of AffiliateStatsService, validates cache TTL environment variable parsing, and confirms dependency injection correctness.
Affiliate Route Error Logging
apps/api/src/app/routes/affiliate/affiliate-stats/_address/index.ts, apps/api/src/app/routes/affiliate/trader-stats/_address/index.ts
Updates error logging in catch blocks from positional argument to structured field format ({ err: error }) for consistent log payload shape.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 The container now sings with singleton grace,
One service instance in its stable place,
TTLs tick faster, logs structured and clear,
With tests watching closely—no bugs will appear!
A rabbit's delight: dependency injection done right! 🌰✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title addresses multiple changes: singleton caching for AffiliateStatsService, updated cache TTL default, structured error logging in affiliate routes, and exporting getApiContainer—all present in the changeset.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/affiliate-trader-activity

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 and usage tips.

@kernelwhisperer kernelwhisperer changed the title feat(affiliate): trader activity table fix(affiliate): dune caching & error repoting Apr 29, 2026
@kernelwhisperer kernelwhisperer self-assigned this Apr 29, 2026
@kernelwhisperer kernelwhisperer marked this pull request as ready for review April 29, 2026 10:08
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
apps/api/src/app/inversify.config.ts (2)

77-93: Double-check the new default TTL.

Dropping the fallback from 1 hour to 5 minutes is a 12x increase in cache churn and upstream Dune calls. If that freshness improvement is intentional, fine; otherwise keep the longer default and rely on the env override for shorter-lived environments.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/api/src/app/inversify.config.ts` around lines 77 - 93, The default cache
TTL was reduced to 5 minutes which increases upstream Dune calls; revert the
DEFAULT_AFFILIATE_STATS_CACHE_TTL_MS to the original 1 hour (3600*1000 ms) in
the file and keep the getAffiliateStatsCacheTtlMs() logic and
DUNE_AFFILIATE_STATS_CACHE_TTL_MS env override unchanged so environments can
still opt into shorter TTLs if desired.

96-228: Avoid two public container entry points unless both are intentional.

getApiContainer() creates a fresh Container, while apiContainer remains a module-level singleton. Any runtime caller that switches to the factory will get a separate AffiliateStatsService cache, so the new singleton scope becomes container-local rather than process-wide. If the factory is only for tests, keep it internal; otherwise document that callers must share one container instance.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/api/src/app/inversify.config.ts` around lines 96 - 228, The module
currently exposes two public entry points (getApiContainer and apiContainer)
causing services bound with inSingletonScope (e.g., AffiliateStatsService bound
via affiliateStatsServiceSymbol with inSingletonScope) to become container-local
rather than process-wide; fix by making a single public container: either make
getApiContainer non-exported (keep only the module-level apiContainer export) or
remove the apiContainer export and document/export only the factory and ensure
callers share its instance; update usages/tests to obtain the same container
(use apiContainer or call a single exported factory wrapper) so
AffiliateStatsService and other singletons remain process-wide.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@apps/api/src/app/inversify.config.ts`:
- Around line 77-93: The default cache TTL was reduced to 5 minutes which
increases upstream Dune calls; revert the DEFAULT_AFFILIATE_STATS_CACHE_TTL_MS
to the original 1 hour (3600*1000 ms) in the file and keep the
getAffiliateStatsCacheTtlMs() logic and DUNE_AFFILIATE_STATS_CACHE_TTL_MS env
override unchanged so environments can still opt into shorter TTLs if desired.
- Around line 96-228: The module currently exposes two public entry points
(getApiContainer and apiContainer) causing services bound with inSingletonScope
(e.g., AffiliateStatsService bound via affiliateStatsServiceSymbol with
inSingletonScope) to become container-local rather than process-wide; fix by
making a single public container: either make getApiContainer non-exported (keep
only the module-level apiContainer export) or remove the apiContainer export and
document/export only the factory and ensure callers share its instance; update
usages/tests to obtain the same container (use apiContainer or call a single
exported factory wrapper) so AffiliateStatsService and other singletons remain
process-wide.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0d78e598-adfe-4476-a266-893c7ad48013

📥 Commits

Reviewing files that changed from the base of the PR and between 6a9c693 and 6732502.

📒 Files selected for processing (4)
  • apps/api/src/app/inversify.config.spec.ts
  • apps/api/src/app/inversify.config.ts
  • apps/api/src/app/routes/affiliate/affiliate-stats/_address/index.ts
  • apps/api/src/app/routes/affiliate/trader-stats/_address/index.ts

@kernelwhisperer kernelwhisperer requested a review from a team April 29, 2026 10:17
@kernelwhisperer
Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 29, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@socket-security
Copy link
Copy Markdown

socket-security Bot commented Apr 29, 2026

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedpg@​8.13.1991009887100
Addedeslint-plugin-prettier@​4.2.59910010090100

View full report

@kernelwhisperer kernelwhisperer force-pushed the feat/affiliate-trader-activity branch from 09903b0 to 8a40402 Compare April 29, 2026 10:39
@kernelwhisperer kernelwhisperer changed the title fix(affiliate): dune caching & error repoting fix(affiliate): dune caching & error repoting & linting Apr 29, 2026
lastUpdatedAt: result.lastUpdatedAt,
});
} catch (error) {
fastify.log.error('Error fetching affiliate trader stats:', error);
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.

Not urgent, but if both the previous version and the new one are correct, but behave differently, maybe we should create a util function so that we don't make this mistake again?

@kernelwhisperer kernelwhisperer merged commit ac17763 into main May 5, 2026
9 checks passed
@kernelwhisperer kernelwhisperer deleted the feat/affiliate-trader-activity branch May 5, 2026 09:49
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.

3 participants