Skip to content

get_stations_by_line_group_id_vecで列車種別を一括取得してセット#1390

Merged
TinyKitten merged 4 commits into
devfrom
fix/tt-batch
Feb 8, 2026
Merged

get_stations_by_line_group_id_vecで列車種別を一括取得してセット#1390
TinyKitten merged 4 commits into
devfrom
fix/tt-batch

Conversation

@TinyKitten

@TinyKitten TinyKitten commented Feb 8, 2026

Copy link
Copy Markdown
Member

#1389 でtrainTypeが含まれていないレスポンスを返していたので下記の修正を適用:
N+1問題を回避しつつ、train_type_repository.get_by_line_group_id_vecで 複数line_group_idの列車種別を1クエリで取得し、top-levelとlines[].station の両方にセットするよう修正。

Summary by CodeRabbit

リリースノート

  • 改善

    • ステーション情報レスポンスに列車種別(train_type)が統合されました。
    • 同一レスポンス内のネストされた駅参照にも列車種別が付与され、より詳細で一貫した駅データを提供します。
    • 公開APIの署名に変更はありません。
  • テスト

    • トップレベルおよびネストされた駅への列車種別付与を検証するテストが追加されました。

N+1問題を回避しつつ、train_type_repository.get_by_line_group_id_vecで
複数line_group_idの列車種別を1クエリで取得し、top-levelとlines[].station
の両方にセットするよう修正。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@TinyKitten TinyKitten self-assigned this Feb 8, 2026
@coderabbitai

coderabbitai Bot commented Feb 8, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

get_stations_by_line_group_id_vecがline_group_idsでtrain typeを一括取得し、station_cdをキーにしたマップを作成してトップレベルのStationと各line内のネストされたline.station参照にtrain_typeを割り当てる処理が追加されました。テストが追加・拡張されています。

Changes

Cohort / File(s) Summary
Train Type 注入 (interactor)
stationapi/src/use_case/interactor/query.rs
get_stations_by_line_group_id_vectrain_type_repository.get_by_line_group_id_vec(line_group_ids)をバルク取得し、station_cdをキーにしたマップを構築してトップレベルのStationと各line.stationtrain_typeを設定するロジックを追加。関連テストが追加・拡張され、空入力等のケースも含まれる。

Sequence Diagram(s)

sequenceDiagram
    participant Client as Client
    participant Interactor as Interactor\n(get_stations_by_line_group_id_vec)
    participant StationRepo as StationRepository
    participant TrainTypeRepo as TrainTypeRepository
    participant Mapper as TrainTypeMap
    participant Enricher as StationEnricher

    rect rgba(100,150,240,0.5)
    Client->>Interactor: リクエスト(line_group_id_vec, transport_type)
    Interactor->>StationRepo: get_stations_by_line_group_id_vec(...)
    StationRepo-->>Interactor: stations[]
    end

    rect rgba(120,200,100,0.5)
    Interactor->>TrainTypeRepo: get_by_line_group_id_vec(line_group_ids)
    TrainTypeRepo-->>Interactor: train_types[]
    Interactor->>Mapper: build map keyed by station_cd
    Mapper-->>Interactor: train_type_map
    end

    rect rgba(240,180,80,0.5)
    Interactor->>Enricher: enrich stations with train_type_map (top-level + line.station)
    Enricher-->>Interactor: enriched stations[]
    Interactor-->>Client: return enriched stations[]
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

🐰 ちょこっと跳んで線を辿り、
まとめて集めたtrain typeの種。
ネストの奥にもふわり置けば、
駅たちがにっこり応えるよ🚆
小さな耳で祝う春の改良。

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 36.36% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed プルリクエストのタイトルは、変更内容の主要な部分「get_stations_by_line_group_id_vecで列車種別を一括取得してセット」を正確に反映しており、変更セットの主な目的と完全に関連している。

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/tt-batch

No actionable comments were generated in the recent review. 🎉


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

@TinyKitten TinyKitten marked this pull request as ready for review February 8, 2026 06:23

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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 `@stationapi/src/use_case/interactor/query.rs`:
- Around line 407-443: Add unit tests for get_stations_by_line_group_id_vec by
updating the test module that uses ConfigurableMockTrainTypeRepository:
implement ConfigurableMockTrainTypeRepository::get_by_line_group_id_vec to
return a Vec<TrainType> containing TrainType entries with station_cd set for the
stations created in the test, then call the interactor method (the same flow
that uses update_station_vec_with_attributes and
train_type_repository.get_by_line_group_id_vec) and assert that top-level
station.train_type and nested line.station.train_type are Some and match the
expected TrainType values; use the existing pattern from tests around
update_station_vec_with_attributes to configure mocks and run the test with
cargo test --lib --package stationapi.
🧹 Nitpick comments (1)
stationapi/src/use_case/interactor/query.rs (1)

417-420: HashMap構築時のfilter_mapパターンは既存コードと一貫しています。

station_cdNoneのTrainTypeを除外する処理は適切です。ただし、このパターンはupdate_station_vec_with_attributes(286-289行目)と重複しているため、将来的にヘルパー関数への抽出を検討できます。

♻️ オプション:ヘルパー関数の抽出案
// QueryInteractor impl ブロック内に追加
fn build_train_type_map_by_station_cd(train_types: &[TrainType]) -> std::collections::HashMap<i32, &TrainType> {
    train_types
        .iter()
        .filter_map(|tt| tt.station_cd.map(|cd| (cd, tt)))
        .collect()
}

Comment thread stationapi/src/use_case/interactor/query.rs
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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 `@stationapi/src/use_case/interactor/query.rs`:
- Around line 2554-2613: テスト
test_get_stations_by_line_group_id_vec_populates_nested_train_type はネストされた
lines[].station の train_type が None のまま通ってしまう可能性があるので、ループ内で単に比較するだけでなく各ネスト済み駅の
train_type が Some であることを明示的に検証してください;具体的には
QueryInteractor::get_stations_by_line_group_id_vec の戻り値から得た station_result.lines
を走査し、各 line.station が存在する場合は nested_station.train_type.is_some() を assert してから
nested_station.train_type.as_ref().unwrap().type_name が "快速"
であることをチェックするように修正してください。

Comment thread stationapi/src/use_case/interactor/query.rs

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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 `@stationapi/src/use_case/interactor/query.rs`:
- Around line 422-440: The loop in update_station_vec_with_attributes leaves old
train_type values when train_type_map lacks an entry; ensure station.train_type
and nested_station.train_type are always overwritten from train_type_map: look
up the key in train_type_map (used in the for station in stations.iter_mut loop
and the nested for line in station.lines.iter_mut block), set the field to
Some(boxed_value) when found and explicitly set to None when not found so
previous values cannot leak across iterations.

Comment thread stationapi/src/use_case/interactor/query.rs Outdated
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@TinyKitten TinyKitten merged commit 9fe1da9 into dev Feb 8, 2026
10 checks passed
@TinyKitten TinyKitten deleted the fix/tt-batch branch February 8, 2026 06:59
TinyKitten added a commit that referenced this pull request Feb 8, 2026
* GetStationsByLineIdList RPC追加

複数のline_idを一括で処理するバッチRPCを追加。
既存のGetStationByIdList/GetLineByIdListと同じバッチパターンに従う。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* cargo fmt

* get_by_line_id_vecのORDER BYを入力順序保持のCASE式に変更

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Merge pull request #1389 from TrainLCD/feature/tt-batch

GetStationsByLineGroupIdList RPC追加

* get_stations_by_line_group_id_vecで列車種別を一括取得してセット (#1390)

* get_stations_by_line_group_id_vecで列車種別を一括取得してセット

N+1問題を回避しつつ、train_type_repository.get_by_line_group_id_vecで
複数line_group_idの列車種別を1クエリで取得し、top-levelとlines[].station
の両方にセットするよう修正。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* get_stations_by_line_group_id_vecのユニットテストを追加

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* ネストされた駅のtrain_typeをis_some()で明示的に検証するよう修正

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* train_typeをtrain_type_mapから常に上書きしてリーク防止

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
TinyKitten added a commit that referenced this pull request Mar 6, 2026
* master<-dev (#1337)

* GetRoutesMinimal RPCを実装 (#1334)

* Add minimal route retrieval functionality and related proto types

* Refactor code formatting for improved readability in grpc.rs and query.rs

* Add line symbols to LineMinimal in get_lines_by_station_group_id

* Update subproject commit reference in stationapi/proto

* Add get_lines_by_id_list method and update QueryUseCase trait

* Refactor import order for improved readability in grpc.rs

* Use entry method for inserting line_minimal in all_lines to avoid overwriting

* Refactor route_row_tree_map creation into a separate build_route_tree_map method for improved readability

* Enhance line symbol handling in QueryInteractor: populate line_symbols for all lines and update line_minimal entries conditionally

* Refactor line symbol handling in QueryInteractor: update all_lines conditionally based on line_symbols presence

* Add AGENTS.md for automation agent and contributor workflow guidelines

* Update AGENTS.md

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* 石橋阪大前駅ローカライズ修正 (#1336)

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* master<-dev (#1374)

* SQLの致命的なバグをいくつか修正 (#1371)

* ひらがな混じりで駅検索ができないバグを修正

* get_train_types_by_station_idが動かないバグを修正

* GetStationsByLineGroupIdの修正

* ユニットテスト拡充

* cargo fmt

* バス路線はline_typeをOtherLineTypeに強制 (#1372)

* direction_idがNULLのトリップに存在するバス停も正しく取り込むよう修正 (#1373)

* direction_idがNULLのトリップに存在するバス停も正しく取り込むよう修正

GTFSの仕様ではdirection_idはオプショナルであり、NULLの場合でも
バス停は有効な停留所として扱うべきである。

これまではvariant_only_with_neighbors CTEで「direction_id IS NOT NULL」
のトリップにのみ存在するバス停をフィルタリングしていたため、
早81の原宿駅前や渋谷駅東口などのバス停がレスポンスから除外されていた。

* バリアントバス停の位置推定でメイントリップに存在する隣接バス停を優先

variant_only_with_neighborsでバス停の隣接情報を選択する際に、
隣接バス停(prev_stop_id/next_stop_id)がメイントリップに存在する
レコードを優先するよう修正。

これにより、原宿駅前などのバス停がより正確な位置に挿入される。

---------

Co-authored-by: Claude <noreply@anthropic.com>

---------

Co-authored-by: Claude <noreply@anthropic.com>

* 西鉄データ更新 (#1375)

* 春日原駅を特急停車駅に指定

* 聖マリア病院前の駅名修正

* master<-dev (#1391)

* GetStationsByLineIdList RPC追加

複数のline_idを一括で処理するバッチRPCを追加。
既存のGetStationByIdList/GetLineByIdListと同じバッチパターンに従う。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* cargo fmt

* get_by_line_id_vecのORDER BYを入力順序保持のCASE式に変更

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Merge pull request #1389 from TrainLCD/feature/tt-batch

GetStationsByLineGroupIdList RPC追加

* get_stations_by_line_group_id_vecで列車種別を一括取得してセット (#1390)

* get_stations_by_line_group_id_vecで列車種別を一括取得してセット

N+1問題を回避しつつ、train_type_repository.get_by_line_group_id_vecで
複数line_group_idの列車種別を1クエリで取得し、top-levelとlines[].station
の両方にセットするよう修正。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* get_stations_by_line_group_id_vecのユニットテストを追加

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* ネストされた駅のtrain_typeをis_some()で明示的に検証するよう修正

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* train_typeをtrain_type_mapから常に上書きしてリーク防止

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>

* 近鉄種別修正

* 近鉄種別修正

駅コード修正

---------

Co-authored-by: Tsubasa SEKIGUCHI <oss@tinykitten.me>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>
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