Skip to content

refactor(backend): extract easy duplicated helpers - #2806

Open
riderx wants to merge 3 commits into
mainfrom
refactor/extract-easy-duplicated-helpers
Open

refactor(backend): extract easy duplicated helpers#2806
riderx wants to merge 3 commits into
mainfrom
refactor/extract-easy-duplicated-helpers

Conversation

@riderx

@riderx riderx commented Jul 31, 2026

Copy link
Copy Markdown
Member

Summary (AI generated)

  • Extract shared generateDateLabels into utils/stats_date_range.ts (was copied in 4 stats handlers)
  • Move chart dataset builders into utils/version_stats_helpers.ts (createPercentageDatasetsByName / createDatasetsByName)
  • Extract getEffectiveApikey / requireEffectiveApikey into utils/effective_apikey.ts
  • Deduplicate channel GET snake_case → camelCase mapping via mapChannelRowToPublic

Motivation (AI generated)

These were clear, low-risk copy-paste clusters from a duplication audit. Factorizing them reduces drift (especially chart/date labeling) without touching hot plugin paths or intentional plugin-folder duplication.

Business Impact (AI generated)

No user-facing behavior change. Lower maintenance cost and fewer places to fix when stats charts or channel API shape evolve.

Test Plan (AI generated)

  • bunx vitest run tests/channel-stats.unit.test.ts tests/bundle-usage.unit.test.ts tests/update-delivery-stats.unit.test.ts tests/native-observe-stats.unit.test.ts (38 passed)
  • bun lint:backend
  • CI backend/unit shards green
  • Spot-check channel GET list + single response still camelCase for rollout/auto-pause fields

Generated with AI

Made with Cursor

Review in cubic

Deduplicate generateDateLabels, chart dataset builders, effective API key
resolution, and channel GET camelCase mapping across public/private routes.

Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 16 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: 54f235ca-529f-4570-97c1-6382dd9b91f5

📥 Commits

Reviewing files that changed from the base of the PR and between 266de4a and bbbe2af.

📒 Files selected for processing (12)
  • supabase/functions/_backend/private/channel_stats.ts
  • supabase/functions/_backend/private/native_observe_stats.ts
  • supabase/functions/_backend/private/update_delivery_stats.ts
  • supabase/functions/_backend/public/bundle/set_channel.ts
  • supabase/functions/_backend/public/channel/delete.ts
  • supabase/functions/_backend/public/channel/get.ts
  • supabase/functions/_backend/public/channel/post.ts
  • supabase/functions/_backend/public/device/post.ts
  • supabase/functions/_backend/public/statistics/index.ts
  • supabase/functions/_backend/utils/effective_apikey.ts
  • supabase/functions/_backend/utils/stats_date_range.ts
  • supabase/functions/_backend/utils/version_stats_helpers.ts

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

@codspeed-hq

codspeed-hq Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 43 untouched benchmarks
⏩ 2 skipped benchmarks1


Comparing refactor/extract-easy-duplicated-helpers (bbbe2af) with main (449b2a6)

Open in CodSpeed

Footnotes

  1. 2 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Knip flagged createDatasetsByName as a duplicate export of
createPercentageDatasetsByName; keep one export and alias only in tests.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@sonarqubecloud

Copy link
Copy Markdown

@riderx
riderx marked this pull request as ready for review July 31, 2026 01:41

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Risk: low. Approved after Cursor Bugbot completed successfully with no findings requiring human review. No reviewers assigned.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Approver External

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Risk: low. Approved after Cursor Bugbot completed successfully with no findings requiring human review. No reviewers assigned.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Approver

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No issues found across 12 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

@riderx

riderx commented Jul 31, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

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.

@riderx

riderx commented Jul 31, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

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.

@riderx

riderx commented Jul 31, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

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.

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