Skip to content

fix: correct staleAfterMs unit and remove dead facade method#701

Open
kamilwronka wants to merge 1 commit intodevelopfrom
claude/friendly-allen
Open

fix: correct staleAfterMs unit and remove dead facade method#701
kamilwronka wants to merge 1 commit intodevelopfrom
claude/friendly-allen

Conversation

@kamilwronka
Copy link
Copy Markdown
Contributor

@kamilwronka kamilwronka commented Apr 7, 2026

Summary

  • guilds.service.ts: Fix staleAfterMs initialization — was storing raw seconds from channelSnapshotStaleSeconds instead of multiplying by 1000 to get milliseconds. This caused the staleness check (Date.now() - updatedAt > staleAfterMs) to treat guild Discord sync as stale after ~300ms instead of ~5min, triggering unnecessary refresh calls. Now matches channels.service.ts behavior.
  • events.service.ts: Remove unused calculateMemberPoints facade method (no callers outside its spec file) and its sole import DEFAULT_ADVANCED_EVENT_SCORING_RULES.
  • events.service.spec.ts: Remove corresponding mock setup and test case.

Why each change is safe

  1. staleAfterMs fix: Corrects a unit mismatch bug. The variable name (staleAfterMs) and comparison target (Date.now()) both expect milliseconds. The identical pattern in channels.service.ts already uses * 1000.
  2. Dead code removal: Grep across the entire monorepo confirms calculateMemberPoints on the facade has zero callers outside the spec. The real scoring logic lives in EventPointsService.calculateMemberPoints which is called directly.

Touched files

  • apps/api/src/guilds/guilds.service.ts (1 line)
  • apps/api/src/events/events.service.ts (removed 27 lines)
  • apps/api/src/events/events.service.spec.ts (removed 16 lines)

Residual risks

  • The staleAfterMs fix changes runtime behavior: guild Discord sync will refresh less frequently (correct 5-min threshold vs previous ~instant). This is the intended behavior based on the config name and the channels.service.ts reference implementation.

Test plan

  • All 598 unit tests pass (52/52 test files)
  • TypeScript type check passes (tsc --noEmit)
  • Lint passes (only pre-existing warnings)
  • Format check passes on changed files

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Fixed Discord guild synchronization staleness threshold calculation to correctly measure refresh intervals.
  • Refactor

    • Removed event points calculation method from service layer.
  • Tests

    • Cleaned up event points delegation test cases.

…facade

- guilds.service.ts: multiply channelSnapshotStaleSeconds by 1000 to get
  milliseconds, matching channels.service.ts (was comparing seconds against
  Date.now() milliseconds, causing overly-aggressive refresh)
- events.service.ts: remove unused calculateMemberPoints facade method and
  its sole import DEFAULT_ADVANCED_EVENT_SCORING_RULES (no callers outside
  spec file)
- events.service.spec.ts: remove corresponding mock and test for the
  deleted method

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 7, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c359652d-0a8d-4487-8198-49492db82e56

📥 Commits

Reviewing files that changed from the base of the PR and between f99033e and ab0ae67.

📒 Files selected for processing (3)
  • apps/api/src/events/events.service.spec.ts
  • apps/api/src/events/events.service.ts
  • apps/api/src/guilds/guilds.service.ts
💤 Files with no reviewable changes (2)
  • apps/api/src/events/events.service.spec.ts
  • apps/api/src/events/events.service.ts

📝 Walkthrough

Walkthrough

The pull request removes the calculateMemberPoints method from EventsService along with its corresponding test, and fixes a unit conversion bug in GuildsService where staleness threshold configuration is now properly converted from seconds to milliseconds during initialization.

Changes

Cohort / File(s) Summary
EventsService Cleanup
apps/api/src/events/events.service.ts, apps/api/src/events/events.service.spec.ts
Deleted calculateMemberPoints method and its delegation test, including removal of related mock setup and imports.
GuildsService Configuration Fix
apps/api/src/guilds/guilds.service.ts
Updated staleAfterMs initialization to multiply channelSnapshotStaleSeconds by 1000, converting the configuration value from seconds to milliseconds for correct staleness threshold calculations.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 We hop through the code, deleting with care,
Removing old methods that linger there,
A thousand milliseconds now multiply true,
Time checks work better—our Discord guild queue! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the two main changes: fixing the staleAfterMs unit conversion and removing the dead calculateMemberPoints method.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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 claude/friendly-allen

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.

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