Skip to content

Increase default stop arrival fetch count - #30

Merged
rsun19 merged 1 commit into
mainfrom
add-more-fetching
Apr 14, 2026
Merged

rsun19 merged 1 commit into
mainfrom
add-more-fetching

Conversation

@rsun19

@rsun19 rsun19 commented Apr 14, 2026

Copy link
Copy Markdown
Owner

Summary

  • Increased the default value for stop arrival search results (DEFAULT_STOP_SEARCH_LIMIT) to 30, allowing more arrivals to be fetched per request.
  • Updated backend logic to use the new default where applicable.
  • Improves user experience by displaying more upcoming arrivals at once, reducing the need for additional fetches.

Technical details:

  • Changed the DEFAULT_STOP_SEARCH_LIMIT constant in the backend.
  • All endpoints and services using this constant now return up to 30 arrivals by default.

Why:

  • Users requested to see more arrivals per stop without extra clicks or requests.
  • This change optimizes the display of transportation arrival information and reduces API round-trips.

Testing:

  • Verified that stop arrival endpoints now return up to 30 results by default.
  • Confirmed no regressions in pagination or limit enforcement.

Closes #30 if applicable.

@coderabbitai

coderabbitai Bot commented Apr 14, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Adds a new constant DEFAULT_STOP_SEARCH_LIMIT set to 30 and updates the getArrivals() method in StopsService to use this new constant as its default limit parameter instead of the generic DEFAULT_SEARCH_LIMIT.

Changes

Cohort / File(s) Summary
Constants Definition
backend/src/common/constants.ts
Adds new exported constant DEFAULT_STOP_SEARCH_LIMIT with value 30 for stop-specific search result pagination.
Service Parameter Update
backend/src/modules/stops/stops.service.ts
Updates getArrivals() method default parameter from DEFAULT_SEARCH_LIMIT to DEFAULT_STOP_SEARCH_LIMIT, changing the default page size for stop arrival queries.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Poem

🐰 A stop search limit, oh what a treat!
Thirty arrivals, a tidy retreat.
Constants defined, parameters refined,
Better defaults for searches aligned! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title accurately describes the main change: introducing a new constant to increase the default limit for stop arrival fetches from the default search limit to 30.

✏️ 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 add-more-fetching

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.

@rsun19 rsun19 changed the title increased fetch stop default count Increase default stop arrival fetch count Apr 14, 2026

@coderabbitai coderabbitai 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
backend/src/modules/stops/stops.service.ts (1)

184-188: ⚠️ Potential issue | 🟠 Major

Normalize limit before building the cache key.

Line [187] keys by raw limit, but Line [328] caps it. This can fragment cache entries and waste Redis memory for identical result sets.

Proposed fix
   async getArrivals(
     stopId: string,
     agencyKey: string,
     limit = DEFAULT_STOP_SEARCH_LIMIT,
     after?: string,
   ): Promise<{ data: ArrivalResponse[]; stopId: string; agencyKey: string; stopName: string }> {
-    const cacheKey = `cache:arrivals:v3:${agencyKey}:${stopId}:${limit}:${after ?? 'now'}`;
+    const cappedLimit = Math.min(limit, MAX_SEARCH_LIMIT);
+    const cacheKey = `cache:arrivals:v3:${agencyKey}:${stopId}:${cappedLimit}:${after ?? 'now'}`;
@@
-        Math.min(limit, MAX_SEARCH_LIMIT),
+        cappedLimit,
       ],
     );

Also applies to: 328-329

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

In `@backend/src/modules/stops/stops.service.ts` around lines 184 - 188, Normalize
the incoming limit before building cacheKey to avoid fragmented Redis entries:
compute a normalizedLimit using the same capping logic applied later (e.g.,
normalizedLimit = Math.min(limit, DEFAULT_STOP_SEARCH_LIMIT) or call the
existing cap used around lines 328-329), then use normalizedLimit (not raw
limit) when creating cacheKey
(`cache:arrivals:v3:${agencyKey}:${stopId}:${normalizedLimit}:${after ??
'now'}`) so cache keys match the actual query size used by the rest of the
function.
🧹 Nitpick comments (1)
backend/src/common/constants.ts (1)

36-36: Clarify constant intent to avoid misuse.

DEFAULT_STOP_SEARCH_LIMIT is easy to confuse with the existing search-page default. Consider renaming it to an arrivals-specific name (or add a clear comment) so future call sites don’t apply it to the wrong endpoint.

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

In `@backend/src/common/constants.ts` at line 36, The constant
DEFAULT_STOP_SEARCH_LIMIT is ambiguous and may be misused; rename it to
something arrivals-specific (e.g., ARRIVALS_DEFAULT_SEARCH_LIMIT) or add a clear
inline comment above DEFAULT_STOP_SEARCH_LIMIT clarifying it's only for
arrivals/stop-arrivals endpoint; update all references/usages (imports, tests,
and any modules that consume DEFAULT_STOP_SEARCH_LIMIT) to the new name or rely
on the clarified comment so callers for the search-page default are not
accidentally using this value.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@backend/src/modules/stops/stops.service.ts`:
- Around line 184-188: Normalize the incoming limit before building cacheKey to
avoid fragmented Redis entries: compute a normalizedLimit using the same capping
logic applied later (e.g., normalizedLimit = Math.min(limit,
DEFAULT_STOP_SEARCH_LIMIT) or call the existing cap used around lines 328-329),
then use normalizedLimit (not raw limit) when creating cacheKey
(`cache:arrivals:v3:${agencyKey}:${stopId}:${normalizedLimit}:${after ??
'now'}`) so cache keys match the actual query size used by the rest of the
function.

---

Nitpick comments:
In `@backend/src/common/constants.ts`:
- Line 36: The constant DEFAULT_STOP_SEARCH_LIMIT is ambiguous and may be
misused; rename it to something arrivals-specific (e.g.,
ARRIVALS_DEFAULT_SEARCH_LIMIT) or add a clear inline comment above
DEFAULT_STOP_SEARCH_LIMIT clarifying it's only for arrivals/stop-arrivals
endpoint; update all references/usages (imports, tests, and any modules that
consume DEFAULT_STOP_SEARCH_LIMIT) to the new name or rely on the clarified
comment so callers for the search-page default are not accidentally using this
value.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fd547dec-b9e4-44ab-ba3e-b401e1cc46b8

📥 Commits

Reviewing files that changed from the base of the PR and between 0b44947 and a5f5caf.

📒 Files selected for processing (2)
  • backend/src/common/constants.ts
  • backend/src/modules/stops/stops.service.ts

@rsun19
rsun19 merged commit 6bc3fbc into main Apr 14, 2026
12 checks passed
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