Skip to content

master<-dev#1447

Merged
TinyKitten merged 1 commit into
masterfrom
dev
Mar 22, 2026
Merged

master<-dev#1447
TinyKitten merged 1 commit into
masterfrom
dev

Conversation

@TinyKitten
Copy link
Copy Markdown
Member

No description provided.

…#1446)

* Batch bus-related queries to eliminate N+1 in GetStationsByLineIdList

When transport_type=RailAndBus with many line_ids, the endpoint suffered
from 100+ sequential DB queries for bus stop enrichment. This change
batches all bus-related queries before the main loop:

1. Add get_bus_stops_near_stations using LATERAL JOIN + UNNEST to fetch
   all nearby bus stops in a single query instead of per-station calls
2. Pre-fetch all bus lines in one get_by_station_group_id_vec call
3. Merge bus company IDs into the Phase 2 company fetch
4. Add get_by_station_group_id_vec_no_types to LineRepository to skip
   unnecessary station_station_types JOIN when skip_types_join=true

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Fix bus stop transport_type filter using DB value instead of proto value

The LATERAL JOIN SQL hardcoded transport_type=2 (proto Bus value) instead
of using the DB value (TransportType::Bus = 1). Changed to parameterized
bind using TransportType::Bus as i32 to match the existing get_by_coordinates
pattern.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Fix bus line ordering and restore pass=1 exclusion in lines query

- Revert lines query to use get_lines_by_station_group_id_vec (with
  station_station_types JOIN) to preserve pass=1 exclusion filtering.
  The _no_types variant incorrectly removed this filter.
- Iterate nearby_bus_stops in distance order (not HashSet) when
  collecting bus lines to preserve deterministic ordering.
- Use entry().or_insert() for bus_stop_by_line_cd so the first
  (closest) bus stop per line_cd wins instead of the last.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Add ORDER BY to outer query in get_bus_stops_near_stations

The LATERAL subquery's ORDER BY does not guarantee result ordering in
the outer SELECT. Add explicit ORDER BY ic.source_g_cd, distance to
ensure results are nearest-first per source station, which is required
for the entry().or_insert() logic that picks the closest bus stop per
line.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Restore _no_types lines query with NOT EXISTS pass=1 filter

Replace the LEFT JOIN to station_station_types with a NOT EXISTS
subquery that preserves the pass=1 exclusion while avoiding the row
multiplication from the JOIN. This gives the performance benefit of
skipping the sst JOIN while maintaining correct pass filtering.

A station is excluded only when all its sst records with non-null
line_group_cd have pass=1 (i.e., no non-pass-through entry exists).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Add missing e_status=0 filter on lines JOIN in get_bus_stops_near_stations

The JOIN to the lines table was missing the active-status filter,
which could include inactive/discontinued lines in bus stop results.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@TinyKitten TinyKitten self-assigned this Mar 22, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 22, 2026

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

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3550148e-1bab-42ae-9e19-b736840a2e47

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
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dev

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

@TinyKitten TinyKitten merged commit 2d26504 into master Mar 22, 2026
11 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