Skip to content

refactor: extract clampLimit helper and remove redundant optional chaining#714

Open
kamilwronka wants to merge 1 commit intodevelopfrom
claude/unruffled-shockley
Open

refactor: extract clampLimit helper and remove redundant optional chaining#714
kamilwronka wants to merge 1 commit intodevelopfrom
claude/unruffled-shockley

Conversation

@kamilwronka
Copy link
Copy Markdown
Contributor

@kamilwronka kamilwronka commented Apr 8, 2026

Summary

  • Extract clampLimit helper in ActivitiesQueryService: the expression Math.min(Math.max(limit, 1), 50) was duplicated 3 times across suggestActorNames, suggestWorlds, and suggestClanNames. Extracted into a private clampLimit method.
  • Remove redundant .getTime?.() optional chaining in find-active-event-heroes-by-npc.ts: when createdAt is a Date, .getTime is always defined — the ?. on the method call was unnecessary. Changed .getTime?.() to .getTime().

Files touched

  • apps/activity/src/activities/services/activities-query.service.ts
  • apps/api/src/events/utils/find-active-event-heroes-by-npc.ts

Safety

  • Both changes are behavior-preserving
  • All 599 API tests pass, all 3 activity tests pass
  • Lint and format checks pass on changed files

Test plan

  • Existing tests pass (599 API tests, 3 activity tests)
  • Format check passes (oxfmt --check)
  • Lint passes (oxlint)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor
    • Improved internal code organization and consistency across utility functions to enhance maintainability.

…ining

- Extract duplicated `Math.min(Math.max(limit, 1), 50)` into a private
  `clampLimit` method in ActivitiesQueryService (used 3 times in same file)
- Remove redundant `.getTime?.()` optional chaining in
  find-active-event-heroes-by-npc.ts — if `createdAt` is a Date,
  `.getTime` is always defined, so `.getTime?.()` is unnecessary

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 8, 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: 5e633e9e-0b0b-48fe-a403-2e19a12a4a6d

📥 Commits

Reviewing files that changed from the base of the PR and between f8c52e1 and c066be8.

📒 Files selected for processing (2)
  • apps/activity/src/activities/services/activities-query.service.ts
  • apps/api/src/events/utils/find-active-event-heroes-by-npc.ts

📝 Walkthrough

Walkthrough

Two small refactoring changes: extraction of duplicate clamping logic into a shared helper method within the activities query service, and correction of optional chaining syntax for Date.getTime() invocation in event hero sorting.

Changes

Cohort / File(s) Summary
Clamping Logic Extraction
apps/activity/src/activities/services/activities-query.service.ts
Consolidated inline limit clamping logic (Math.min(Math.max(limit, 1), 50)) across three suggestion methods into a single private clampLimit() helper method. Maintains all existing bounds and downstream behavior.
Optional Chaining Correction
apps/api/src/events/utils/find-active-event-heroes-by-npc.ts
Changed optional chaining syntax for createdAt.getTime() from method-level chaining (createdAt?.getTime?.()) to direct property chaining (createdAt?.getTime()), improving clarity and correctness.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Possibly related PRs

Poem

🐰 A helper's touch, so neat and clean,
Clamps the limits in between,
Optional chains now stand up straight,
Code refactored—simply great! ✨

🚥 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 accurately describes the main refactoring changes: extracting a clampLimit helper and removing redundant optional chaining across two files.
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/unruffled-shockley

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


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