Skip to content

Build trip stop references with the shared builder - #1797

Closed
aaronbrethorst wants to merge 1 commit into
ab/stop-id-singlefrom
ab/stop-references
Closed

aaronbrethorst wants to merge 1 commit into
ab/stop-id-singlefrom
ab/stop-references

Conversation

@aaronbrethorst

Copy link
Copy Markdown
Member

Stacked on #1796. Part of the stop consolidation work (#1771–#1779). No issue filed yet.

What it does

trips-for-route, trips-for-location, and the parent stations in stops-for-location now build stop references with BuildStopReferencesAndRouteIDsForStops, like every other handler. This is a refactor with no intended response change, and it removes 214 lines net.

Root cause

stopReferences existed so one stop could be listed under several IDs, one per agency that referred to it. It had its own route lookup (routeIDsForStops) and its own parent-station pass (appendResolvedParents). After #1794 and #1796, each stop has exactly one ID, so that second builder only duplicates the shared one.

Changes:

  • Callers collect raw stop IDs and pass them to the shared builder.
  • Routes: route references come from each stop's routeIds, through one helper, rawRouteIDsOfStops.
  • Collection only: stopsReferencedBySchedulesAndStatuses is now stopIDsReferencedBySchedulesAndStatuses. It only collects IDs and no longer queries the database.
  • Removed: stopReferences, appendResolvedParents, routeIDsForStops, appendUniqueStopID, and the StopIDMap / StopIDsByBareID parameters.

Testing

  • Test failing on main before this change: n/a (refactor). The behavior tests from Name a trip's stops by their own agency #1794 and Prefix location results with each stop's agency #1796 (TestTripStopIDs_UseTheStopsOwnAgency, TestTripsForRouteHandler_CrossAgencyInterlinedBlock, TestLocationStopIDs_UseTheStopsOwnAgency) and the existing trips-for-route, trips-for-location and stops-for-location suites pass unchanged.
  • Rewritten tests:
    • TestStopReferences is now TestBuildStopReferencesAndRouteIDsForStops_RoutelessStop. It checks a stop with no routes against the shared builder: empty non-null routeIds, "" direction, and a resolved parent.
    • TestStopReferences_DirectionAndCodeMatchBuildStopModel is deleted. References are now built by buildStopModel itself, so there's nothing left to compare.
    • The collectStopIDsFromSchedule tests now expect a set of raw IDs.

Checklist

  • This PR addresses one issue.
  • It is under ~200 changed lines, or the description says why it can't be split.
  • This PR is not a bug fix, or the new or changed test fails on main and passes on this branch.
  • Each commit is one logical change with a clear message.
  • I did not hand-edit sqlc-generated files under gtfsdb/ (db.go, models.go, query.sql.go) or testdata/openapi.yml (synced from upstream).
  • This PR changes no handler, or handlers pass r.Context() to DB/service calls, not context.Background().
  • The response comparison above is filled in, or this PR doesn't change a Java-served response.
  • This PR adds no endpoint, or each new endpoint matches testdata/openapi.yml, has an issue open on OneBusAway/sdk-config, or is outside the SDK and the description says why.
  • I read every line of this diff and can explain it if asked.

Notes for reviewers

  • Route order inside routeIds. Route IDs within each referenced stop now follow the shared builder's natural sort by route name. Before, they came in query order.
  • Failure handling in trips-for-route. If building stop references fails, trips-for-route logs it and returns empty references.stops, as stopReferences did on its route-lookup failure. trips-for-location returns a 500, as its reference builder already did for other failures.

stopReferences existed so one stop could be listed under several IDs,
one per agency that referred to it, with its own route lookup and its
own parent-station pass. Each stop now has one ID, so trips-for-route,
trips-for-location and stops-for-location's parent stations collect
raw stop IDs and build references with
BuildStopReferencesAndRouteIDsForStops, like every other handler.
Route references come from each stop's routeIds through
rawRouteIDsOfStops.

stopReferences, appendResolvedParents, routeIDsForStops and
appendUniqueStopID go, and stopsReferencedBySchedulesAndStatuses no
longer queries the database: it only collects IDs. The stopReferences
tests become a test of the shared builder; the one comparing its
direction and code with buildStopModel has nothing left to compare.
@coderabbitai

coderabbitai Bot commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: a1b03888-5f2d-4b94-8d2f-02fefc3e6491

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@github-actions

Copy link
Copy Markdown

@aaronbrethorst, the PR description does not follow the PR template:

  • No linked issue. Add Fixes #N (or Part of #N) for a triaged issue.
  • Testing: "Manual check:" is empty.
  • Checklist item is not checked: "This PR addresses one issue." If this item doesn't apply to your PR, ask a maintainer.
  • Checklist item is not checked: "I read every line of this diff and can explain it if asked." If this item doesn't apply to your PR, ask a maintainer.

Keep this PR as Draft until these are fixed. This comment updates when the description changes.

@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

Performance Smoke Test Results

Status: PASSED

Metric Value
p(95) latency 1.6 ms
Error rate 0.00%
Total requests 336
Req/sec 11.0

Smoke test config: 5 VUs x 30s. Thresholds: p(95) < 300ms, error rate < 1%.

Full results uploaded as workflow artifact: k6-smoke-summary.

@aaronbrethorst

Copy link
Copy Markdown
Member Author

Closing as superseded. The multi-feed static GTFS spec (#1811, docs/multi-agency-static-feeds-spec.md §10) folds this stack's stop-ID rules into the per-feed default agency and the stored-ID identity model; they return as phases B and C of that plan. The Java-recorded data in testdata/java_parity and the tests on this branch will be reused there. #1806, #1807 and #1810 are not identity work and stay open to be re-cut against main.

@aaronbrethorst
aaronbrethorst deleted the ab/stop-references branch November 8, 2026 18:31
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