Skip to content

Conversation

@troyciesco
Copy link
Contributor

@troyciesco troyciesco commented Jan 8, 2026

closes https://linear.app/ghost/issue/NY-696

  • Sorting on the Growth tab's Sources table was not working due to a parameter name mismatch. The API was sending order, but the backend service was expecting orderBy. This meant the sort parameter was never correctly applied, and data always appeared in the default order
  • This PR fixes the parameter destructuring in ghost/core/core/server/services/stats/referrers-stats-service.js to correctly map the incoming order parameter to the internal orderBy variable.

source-sort

Co-authored-by: troy <troy@ghost.org>
@cursor
Copy link

cursor bot commented Jan 8, 2026

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 8, 2026

Walkthrough

Renames the sorting option used by the referrers stats service from orderBy to order. JSDoc and internal destructuring in ReferrersStatsService.getTopSourcesWithRange were updated to use order, and test calls were updated accordingly. No changes to function signatures, exported surface, or runtime behavior beyond the option key rename.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed The description is well-related to the changeset, explaining the parameter name mismatch issue and how it's being fixed. It provides context about the regression and references the associated issue.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title mentions 'sorting' and 'Sources table' but uses an emoji and doesn't clearly specify that this is a parameter name mismatch fix renaming orderBy to order.

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

✨ Finishing touches
  • 📝 Generate docstrings

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.

@troyciesco troyciesco marked this pull request as ready for review January 8, 2026 19:55
Copy link
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.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In @ghost/core/core/server/services/stats/referrers-stats-service.js:
- Around line 369-370: Tests still pass the old parameter name; update calls to
use the new "order" key so getTopSourcesWithRange(options) receives it
correctly: locate the test calls that currently pass {orderBy: 'signups desc'},
{orderBy: 'source desc'}, and {orderBy: 'signups desc', limit: 3} and rename
those keys to {order: 'signups desc'}, {order: 'source desc'}, and {order:
'signups desc', limit: 3} respectively so they match the function
getTopSourcesWithRange's destructured parameter (order: orderBy).
🧹 Nitpick comments (1)
ghost/core/core/server/services/stats/referrers-stats-service.js (1)

418-447: Optional: Consider documenting or supporting ascending sort order.

The sorting logic at Line 446 always sorts in descending order (valueA < valueB ? 1 : valueA > valueB ? -1 : 0) regardless of the direction specified in the order parameter string (e.g., "signups asc" would still sort descending). While the JSDoc examples only show descending sorts and Line 418's comment mentions "only allow descending sorts for sources," this could be confusing if a caller passes an ascending order.

Consider either:

  1. Updating the JSDoc to explicitly state that only descending order is supported
  2. Or implementing ascending sort support by parsing and using the direction from the orderBy string
📝 Option 1: Document descending-only behavior
-     * @param {string} [options.order='signups desc'] - Sort order: 'signups desc', 'paid_conversions desc', 'mrr desc', 'source desc'
+     * @param {string} [options.order='signups desc'] - Sort order (descending only): 'signups desc', 'paid_conversions desc', 'mrr desc', 'source desc'
📜 Review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cbd3ef8 and 7c9efc5.

📒 Files selected for processing (2)
  • ghost/core/core/server/services/stats/referrers-stats-service.js
  • ghost/core/core/server/services/stats/stats-service.js
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2026-01-08T10:26:38.700Z
Learnt from: rob-ghost
Repo: TryGhost/Ghost PR: 25791
File: ghost/core/core/server/api/endpoints/member-comment-ban.js:64-68
Timestamp: 2026-01-08T10:26:38.700Z
Learning: In the Ghost API, endpoints rely on the serialization layer to prepare frame.data[docName] as a non-empty array before query() executes. Endpoints access frame.data[docName][0] directly (e.g., frame.data.comment_bans[0], frame.data.members[0], frame.data.posts[0]) without per-endpoint validation. This pattern is common across API endpoints. When maintaining or creating endpoints, avoid duplicating validation for frame.data[docName] and ensure the serializer guarantees the shape and non-emptiness. If you add a new endpoint that uses this frame.data[docName], follow the same assumption and avoid redundant checks unless there's a documented exception.

Applied to files:

  • ghost/core/core/server/services/stats/referrers-stats-service.js
  • ghost/core/core/server/services/stats/stats-service.js
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (13)
  • GitHub Check: [Optional] E2E Tests (React 4/4)
  • GitHub Check: E2E Tests (Ember 4/4)
  • GitHub Check: [Optional] E2E Tests (React 3/4)
  • GitHub Check: [Optional] E2E Tests (React 2/4)
  • GitHub Check: E2E Tests (Ember 1/4)
  • GitHub Check: E2E Tests (Ember 2/4)
  • GitHub Check: E2E Tests (Ember 3/4)
  • GitHub Check: [Optional] E2E Tests (React 1/4)
  • GitHub Check: Acceptance tests (Node 22.18.0, sqlite3)
  • GitHub Check: Legacy tests (Node 22.18.0, mysql8)
  • GitHub Check: Ghost-CLI tests
  • GitHub Check: Unit tests (Node 22.18.0)
  • GitHub Check: Acceptance tests (Node 22.18.0, mysql8)
🔇 Additional comments (2)
ghost/core/core/server/services/stats/stats-service.js (1)

235-245: JSDoc parameter name correctly updated.

The JSDoc update from options.orderBy to options.order aligns with the actual parameter name sent by the API and the destructuring change in referrers-stats-service.js. The default value and allowed sort options are preserved.

ghost/core/core/server/services/stats/referrers-stats-service.js (1)

358-368: JSDoc correctly updated to reflect the new parameter name.

The parameter documentation change from options.orderBy to options.order aligns with the destructuring change below and matches the parameter name sent by the API.

@9larsons 9larsons requested a review from cmraible January 8, 2026 21:41
Copy link
Collaborator

@cmraible cmraible left a comment

Choose a reason for hiding this comment

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

Nice one, works for me 👌

@troyciesco troyciesco changed the title Growth tab sorting regression 🐛 Fixed sorting in Growth tab Sources table Jan 9, 2026
@troyciesco troyciesco merged commit 5ecb42e into main Jan 9, 2026
37 checks passed
@troyciesco troyciesco deleted the cursor/NY-696-growth-tab-sorting-regression-6757 branch January 9, 2026 13:35
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.

4 participants