パフォーマンス系の技術負債の一部解消とバグ修正#1363
Conversation
📝 WalkthroughWalkthroughTransportTypeのデフォルトをrail-onlyに変更し、 Changes
Sequence Diagram(s)(該当条件を満たさないため、シーケンス図は割愛します) Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
📜 Recent review detailsConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used📓 Path-based instructions (4)stationapi/src/use_case/**/*.rs📄 CodeRabbit inference engine (AGENTS.md)
Files:
stationapi/src/**/*.rs📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/*.rs📄 CodeRabbit inference engine (AGENTS.md)
Files:
stationapi/src/use_case/interactor/query.rs📄 CodeRabbit inference engine (AGENTS.md)
Files:
🧠 Learnings (5)📓 Common learnings📚 Learning: 2025-11-25T10:50:36.694ZApplied to files:
📚 Learning: 2025-11-25T10:50:36.694ZApplied to files:
📚 Learning: 2025-11-25T10:50:36.694ZApplied to files:
📚 Learning: 2025-11-25T10:50:36.694ZApplied to files:
🧬 Code graph analysis (1)stationapi/src/use_case/interactor/query.rs (4)
⏰ 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). (2)
🔇 Additional comments (5)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
stationapi/src/use_case/interactor/query.rs (1)
973-985: 同一line_cdを持つ複数バス停の扱いについて修正が必要
nearby_bus_stopsからbus_stop_by_line_cdHashMap を構築する際、同じline_cdを持つ複数のバス停がある場合、イテレーション順で最後のバス停だけが保持されます。同じ関数内で
bus_linesはseen_line_cds.insert(line.line_cd)を使用して明示的に line_cd 単位で重複排除されていますが、バス停ソースに対しては同じパターンが適用されていません。このため、複数の近傍バス停が同じ路線に属する場合、距離に基づいた選定ではなく任意のものが選ばれるため、コードベース全体の重複排除パターンと矛盾しています。
nearby_bus_stopsもbus_linesと同じく HashMap 構築前に重複排除するか、動作を明示的にドキュメント化してください。
🧹 Nitpick comments (2)
stationapi/src/use_case/interactor/query.rs (1)
262-275:.cloned().cloned()パターンについて現在の実装は正しく動作しますが、
.cloned().cloned()のチェーンはやや冗長です。Companyの所有権が他で必要ない場合、HashMap をHashMap<i32, Company>として構築することで、単一の.cloned()で済みます。ただし、現在のアプローチも正しく、パフォーマンスへの影響は軽微なため、このままでも問題ありません。
🔎 代替案(オプション)
- let company_map: std::collections::HashMap<i32, &Company> = - companies.iter().map(|c| (c.company_cd, c)).collect(); + let company_map: std::collections::HashMap<i32, Company> = + companies.into_iter().map(|c| (c.company_cd, c)).collect();使用箇所も以下のように変更:
- line.company = company_map.get(&line.company_cd).cloned().cloned(); + line.company = company_map.get(&line.company_cd).cloned();docs/technical_debt.md (1)
287-287: 取り消し線による完了マーク取り消し線(
~~Clone 削減~~)で完了項目を示すのは良いアプローチですが、完全に削除するか、別セクションに移動することも検討してください。長期的には完了項目が蓄積し、ドキュメントが読みにくくなる可能性があります。
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
docs/nearby-bus-stops.mddocs/technical_debt.mdstationapi/src/use_case/interactor/query.rs
🧰 Additional context used
📓 Path-based instructions (5)
stationapi/src/use_case/**/*.rs
📄 CodeRabbit inference engine (AGENTS.md)
Application logic in use case layer should implement contract traits defined in
traits/module (e.g.,QueryUseCaseininteractor/query.rs)
Files:
stationapi/src/use_case/interactor/query.rs
stationapi/src/**/*.rs
📄 CodeRabbit inference engine (AGENTS.md)
Run
cargo test --lib --package stationapiormake test-unitfor unit tests focusing on entities and repository mocks without database
Files:
stationapi/src/use_case/interactor/query.rs
**/*.rs
📄 CodeRabbit inference engine (AGENTS.md)
**/*.rs: Before committing, runcargo fmton all Rust code
Before committing, runcargo clippy --all-targets --all-featuresand resolve new Clippy warnings unless covered by existing#![allow]attributes
Files:
stationapi/src/use_case/interactor/query.rs
stationapi/src/use_case/interactor/query.rs
📄 CodeRabbit inference engine (AGENTS.md)
When modifying
QueryInteractor, ensure enrichment steps (companies, train types, line symbols) still behave as expected and verify helper methods such asupdate_station_vec_with_attributesandbuild_route_tree_map
Files:
stationapi/src/use_case/interactor/query.rs
{docs/**/*.md,README.md}
📄 CodeRabbit inference engine (AGENTS.md)
For database, gRPC, or schema updates, add architectural notes under
docs/and synchronize README references to keep onboarding materials accurate
Files:
docs/technical_debt.mddocs/nearby-bus-stops.md
🧠 Learnings (5)
📓 Common learnings
Learnt from: CR
Repo: TrainLCD/StationAPI PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T10:50:36.694Z
Learning: Applies to stationapi/src/use_case/interactor/query.rs : When modifying `QueryInteractor`, ensure enrichment steps (companies, train types, line symbols) still behave as expected and verify helper methods such as `update_station_vec_with_attributes` and `build_route_tree_map`
📚 Learning: 2025-11-25T10:50:36.694Z
Learnt from: CR
Repo: TrainLCD/StationAPI PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T10:50:36.694Z
Learning: Applies to stationapi/src/use_case/interactor/query.rs : When modifying `QueryInteractor`, ensure enrichment steps (companies, train types, line symbols) still behave as expected and verify helper methods such as `update_station_vec_with_attributes` and `build_route_tree_map`
Applied to files:
stationapi/src/use_case/interactor/query.rsdocs/technical_debt.mddocs/nearby-bus-stops.md
📚 Learning: 2025-11-25T10:50:36.694Z
Learnt from: CR
Repo: TrainLCD/StationAPI PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T10:50:36.694Z
Learning: Applies to stationapi/src/use_case/**/*.rs : Application logic in use case layer should implement contract traits defined in `traits/` module (e.g., `QueryUseCase` in `interactor/query.rs`)
Applied to files:
stationapi/src/use_case/interactor/query.rs
📚 Learning: 2025-11-25T10:50:36.694Z
Learnt from: CR
Repo: TrainLCD/StationAPI PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T10:50:36.694Z
Learning: Applies to stationapi/src/**/*.rs : Run `cargo test --lib --package stationapi` or `make test-unit` for unit tests focusing on entities and repository mocks without database
Applied to files:
stationapi/src/use_case/interactor/query.rsdocs/technical_debt.md
📚 Learning: 2025-11-25T10:50:36.694Z
Learnt from: CR
Repo: TrainLCD/StationAPI PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T10:50:36.694Z
Learning: Applies to stationapi/src/infrastructure/**/*.rs : Integration tests in infrastructure layer must use `#[cfg_attr(not(feature = "integration-tests"), ignore)]` attribute to conditionally ignore tests when the feature is not enabled
Applied to files:
stationapi/src/use_case/interactor/query.rs
🧬 Code graph analysis (1)
stationapi/src/use_case/interactor/query.rs (6)
stationapi/src/domain/entity/train_type.rs (1)
new(26-58)stationapi/src/domain/entity/line.rs (1)
new(48-120)stationapi/src/domain/entity/station.rs (1)
new(84-218)stationapi/src/domain/repository/station_repository.rs (1)
new(61-76)stationapi/src/domain/entity/line_symbol.rs (1)
new(11-17)stationapi/src/domain/entity/station_number.rs (1)
new(12-24)
⏰ 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). (1)
- GitHub Check: Test Suite
🔇 Additional comments (9)
stationapi/src/use_case/interactor/query.rs (5)
991-1003:build_route_tree_mapの参照ベース最適化は良い改善です。
Vec<Station>からVec<&'a Station>への変更により、不要な Station のクローンが回避されます。ライフタイムパラメータ'aも正しく適用されています。Based on learnings,
build_route_tree_mapのヘルパーメソッドが正しく動作することを確認してください。
820-887: TrainType の重複排除と HashMap 検索の最適化
seen_line_group_cdsによる重複排除とtrain_type_by_type_cdによる O(1) 検索への変更は適切です。train_typesの所有権を直接イテレーションで移動することで、不要なクローンも回避されています。
1097-1178: テストヘルパー関数の追加は良いアプローチです。
create_test_stationとcreate_test_lineヘルパー関数により、テストコードの可読性と再利用性が向上しています。Station の全64フィールドを手動で設定する必要がなくなり、テスト作成が容易になります。
1224-1258: Haversine 距離計算のテストカバレッジ同一点、長距離(東京-大阪間約400km)、短距離、および
NEARBY_BUS_STOP_RADIUS_METERS定数との境界テストが含まれており、適切なカバレッジです。
1435-1484:build_route_tree_mapのテストで参照の整合性を確認Line 1483 の
std::ptr::eqによる参照の同一性チェックは、戻り値が元のスライスへの参照であることを保証する良いテストです。docs/technical_debt.md (1)
112-132: 技術負債の対応状況が明確に文書化されています。HashMap ベースの検索最適化、
build_route_tree_mapの参照化、および残存する clone() の理由が適切に説明されています。実装コード(query.rs)と整合性が取れています。docs/nearby-bus-stops.md (3)
7-7: デフォルト動作の変更が明確に文書化されています。後方互換性のためデフォルトを鉄道駅のみに変更したことが明確に説明されています。PR目的(本番環境でバス路線が紛れ込んでいた問題の修正)と整合性があります。
104-106: ヘルパーメソッドのシグネチャ更新
get_nearby_bus_stopsからget_nearby_bus_linesへのリネームと、戻り値型のVec<Station>からVec<Line>への変更が正しく反映されています。実装コード(query.rsLine 934-989)と整合性があります。
110-111: 注意事項の更新
transport_type: RailAndBusを明示的に指定した場合のみ近傍バス路線が追加される動作が明確に説明されています。これにより、デフォルト動作でバス路線が混入しないことが保証されます。
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
stationapi/src/use_case/interactor/query.rs (1)
262-262: HashMap からの効率的な参照取得を確認しました。
company_mapを使用した O(1) ルックアップが正しく実装されています。.cloned().cloned()パターンは機能的に正しいですが、可読性のため.and_then(|c| Some(c.clone()))や.copied()を検討することもできます(ただし、現在のコードで問題はありません)。Also applies to: 301-301
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
stationapi/src/use_case/interactor/query.rs
🧰 Additional context used
📓 Path-based instructions (4)
stationapi/src/use_case/**/*.rs
📄 CodeRabbit inference engine (AGENTS.md)
Application logic in use case layer should implement contract traits defined in
traits/module (e.g.,QueryUseCaseininteractor/query.rs)
Files:
stationapi/src/use_case/interactor/query.rs
stationapi/src/**/*.rs
📄 CodeRabbit inference engine (AGENTS.md)
Run
cargo test --lib --package stationapiormake test-unitfor unit tests focusing on entities and repository mocks without database
Files:
stationapi/src/use_case/interactor/query.rs
**/*.rs
📄 CodeRabbit inference engine (AGENTS.md)
**/*.rs: Before committing, runcargo fmton all Rust code
Before committing, runcargo clippy --all-targets --all-featuresand resolve new Clippy warnings unless covered by existing#![allow]attributes
Files:
stationapi/src/use_case/interactor/query.rs
stationapi/src/use_case/interactor/query.rs
📄 CodeRabbit inference engine (AGENTS.md)
When modifying
QueryInteractor, ensure enrichment steps (companies, train types, line symbols) still behave as expected and verify helper methods such asupdate_station_vec_with_attributesandbuild_route_tree_map
Files:
stationapi/src/use_case/interactor/query.rs
🧠 Learnings (5)
📓 Common learnings
Learnt from: CR
Repo: TrainLCD/StationAPI PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T10:50:36.694Z
Learning: Applies to stationapi/src/use_case/interactor/query.rs : When modifying `QueryInteractor`, ensure enrichment steps (companies, train types, line symbols) still behave as expected and verify helper methods such as `update_station_vec_with_attributes` and `build_route_tree_map`
📚 Learning: 2025-11-25T10:50:36.694Z
Learnt from: CR
Repo: TrainLCD/StationAPI PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T10:50:36.694Z
Learning: Applies to stationapi/src/use_case/interactor/query.rs : When modifying `QueryInteractor`, ensure enrichment steps (companies, train types, line symbols) still behave as expected and verify helper methods such as `update_station_vec_with_attributes` and `build_route_tree_map`
Applied to files:
stationapi/src/use_case/interactor/query.rs
📚 Learning: 2025-11-25T10:50:36.694Z
Learnt from: CR
Repo: TrainLCD/StationAPI PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T10:50:36.694Z
Learning: Applies to stationapi/src/use_case/**/*.rs : Application logic in use case layer should implement contract traits defined in `traits/` module (e.g., `QueryUseCase` in `interactor/query.rs`)
Applied to files:
stationapi/src/use_case/interactor/query.rs
📚 Learning: 2025-11-25T10:50:36.694Z
Learnt from: CR
Repo: TrainLCD/StationAPI PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T10:50:36.694Z
Learning: Applies to stationapi/src/**/*.rs : Run `cargo test --lib --package stationapi` or `make test-unit` for unit tests focusing on entities and repository mocks without database
Applied to files:
stationapi/src/use_case/interactor/query.rs
📚 Learning: 2025-11-25T10:50:36.694Z
Learnt from: CR
Repo: TrainLCD/StationAPI PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T10:50:36.694Z
Learning: Applies to stationapi/src/infrastructure/**/*.rs : Integration tests in infrastructure layer must use `#[cfg_attr(not(feature = "integration-tests"), ignore)]` attribute to conditionally ignore tests when the feature is not enabled
Applied to files:
stationapi/src/use_case/interactor/query.rs
⏰ 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). (1)
- GitHub Check: Test Suite
🔇 Additional comments (9)
stationapi/src/use_case/interactor/query.rs (9)
239-257: LGTM! HashMap による O(1) 検索への最適化が適切に実装されています。
company_map、train_type_map、station_lookupの導入により、従来の線形探索を O(1) のハッシュマップルックアップに置き換えています。特にstation_lookupでタプルキー(line_cd, station_g_cd)を使用している点も適切です。この変更により、エンリッチメント処理のパフォーマンスが大幅に向上します。
Based on learnings, enrichment steps (companies, train types, line symbols) の動作を確認しましたが、正しく機能しています。
268-275: train_type のエンリッチメントが正しく最適化されています。
train_type_mapによる O(1) ルックアップにより、各ステーションに対する TrainType の検索が効率化されています。Box へのラッピングも適切です。Also applies to: 309-316
303-318: station_lookup による複合キー検索が適切に実装されています。
(line_cd, station_g_cd)のタプルキーを使用した O(1) ルックアップにより、ライン情報へのステーション埋め込みが効率化されています。必要な場合のみステーションをクローンしている点も効率的です。
612-621: 過去のレビュー指摘事項が適切に解決されています。
tt_line_mapの導入により、get_routesメソッド内のループで発生していた O(n) 線形探索が O(1) ルックアップに最適化されました。.copied()の使用も効率的です。過去のレビューコメントで指摘されていた線 617 の最適化が正しく実装されています。
823-840: train_type の事前マップ構築と重複排除ロジックが適切です。
train_type_by_type_cdマップの事前構築により、後続のライン埋め込み時の O(1) ルックアップが可能になっています。seen_line_group_cdsによる重複排除ロジックも正しく実装されており、同一line_group_cdの重複を防いでいます。
878-880: TrainType の効率的な埋め込みを確認しました。
train_type_by_type_cdマップを使用した O(1) ルックアップにより、各ラインへの TrainType 埋め込みが効率化されています。
976-984: 近隣バス路線のバス停ルックアップが最適化されています。
bus_stop_by_line_cdマップの導入により、各バス路線に対応するバス停の検索が O(1) で実行できるようになっています。
994-1006: build_route_tree_map の参照版への変更は優れた最適化です。戻り値を
Vec<Station>からVec<&'a Station>に変更することで、不要なクローンを削減しています。ライフタイム注釈も適切に追加されており、借用チェッカーが正しく機能します。Based on learnings,
build_route_tree_mapヘルパーメソッドの動作を確認しましたが、正しく機能しています。
1101-1636: 包括的なテストカバレッジの追加を評価します。以下の機能に対する詳細なテストが追加されています:
haversine_distance: 同一地点、長距離、短距離、バス停半径内外のケースbuild_route_tree_map: 空配列、line_group_cd によるグループ化、line_cd によるグループ化、参照の正しさget_station_numbers: 単一番号、複数番号、空の場合、シンボルなしの場合get_line_symbols: 複数シンボル、フォールバックカラー、空の場合extract_line_from_station: 基本的な抽出、station_cd の保持、オプショナルフィールドの処理モックリポジトリとテストヘルパー関数も適切に実装されており、テストの品質が高いです。
As per coding guidelines,
cargo test --lib --package stationapiでユニットテストを実行して確認することを推奨します。
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
stationapi/src/use_case/interactor/query.rs (1)
262-262: HashMap からの取得パターンが機能していますが、よりクリーンな書き方を検討できます。
.get().cloned().cloned()のパターンは正しく動作しますが、やや冗長です。以下のようなよりクリーンな代替案を検討できます:🔎 オプションのリファクタリング案
-line.company = company_map.get(&line.company_cd).cloned().cloned(); +line.company = company_map.get(&line.company_cd).map(|c| (*c).clone());または
-line.company = company_map.get(&line.company_cd).cloned().cloned(); +line.company = company_map.get(&line.company_cd).copied();(
CompanyがCopyトレイトを実装している場合)Also applies to: 268-275, 301-301, 309-316
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
stationapi/src/use_case/interactor/query.rs
🧰 Additional context used
📓 Path-based instructions (4)
stationapi/src/use_case/**/*.rs
📄 CodeRabbit inference engine (AGENTS.md)
Application logic in use case layer should implement contract traits defined in
traits/module (e.g.,QueryUseCaseininteractor/query.rs)
Files:
stationapi/src/use_case/interactor/query.rs
stationapi/src/**/*.rs
📄 CodeRabbit inference engine (AGENTS.md)
Run
cargo test --lib --package stationapiormake test-unitfor unit tests focusing on entities and repository mocks without database
Files:
stationapi/src/use_case/interactor/query.rs
**/*.rs
📄 CodeRabbit inference engine (AGENTS.md)
**/*.rs: Before committing, runcargo fmton all Rust code
Before committing, runcargo clippy --all-targets --all-featuresand resolve new Clippy warnings unless covered by existing#![allow]attributes
Files:
stationapi/src/use_case/interactor/query.rs
stationapi/src/use_case/interactor/query.rs
📄 CodeRabbit inference engine (AGENTS.md)
When modifying
QueryInteractor, ensure enrichment steps (companies, train types, line symbols) still behave as expected and verify helper methods such asupdate_station_vec_with_attributesandbuild_route_tree_map
Files:
stationapi/src/use_case/interactor/query.rs
🧠 Learnings (5)
📓 Common learnings
Learnt from: CR
Repo: TrainLCD/StationAPI PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T10:50:36.694Z
Learning: Applies to stationapi/src/use_case/interactor/query.rs : When modifying `QueryInteractor`, ensure enrichment steps (companies, train types, line symbols) still behave as expected and verify helper methods such as `update_station_vec_with_attributes` and `build_route_tree_map`
📚 Learning: 2025-11-25T10:50:36.694Z
Learnt from: CR
Repo: TrainLCD/StationAPI PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T10:50:36.694Z
Learning: Applies to stationapi/src/use_case/interactor/query.rs : When modifying `QueryInteractor`, ensure enrichment steps (companies, train types, line symbols) still behave as expected and verify helper methods such as `update_station_vec_with_attributes` and `build_route_tree_map`
Applied to files:
stationapi/src/use_case/interactor/query.rs
📚 Learning: 2025-11-25T10:50:36.694Z
Learnt from: CR
Repo: TrainLCD/StationAPI PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T10:50:36.694Z
Learning: Applies to stationapi/src/use_case/**/*.rs : Application logic in use case layer should implement contract traits defined in `traits/` module (e.g., `QueryUseCase` in `interactor/query.rs`)
Applied to files:
stationapi/src/use_case/interactor/query.rs
📚 Learning: 2025-11-25T10:50:36.694Z
Learnt from: CR
Repo: TrainLCD/StationAPI PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T10:50:36.694Z
Learning: Applies to stationapi/src/**/*.rs : Run `cargo test --lib --package stationapi` or `make test-unit` for unit tests focusing on entities and repository mocks without database
Applied to files:
stationapi/src/use_case/interactor/query.rs
📚 Learning: 2025-11-25T10:50:36.694Z
Learnt from: CR
Repo: TrainLCD/StationAPI PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T10:50:36.694Z
Learning: Applies to stationapi/src/infrastructure/**/*.rs : Integration tests in infrastructure layer must use `#[cfg_attr(not(feature = "integration-tests"), ignore)]` attribute to conditionally ignore tests when the feature is not enabled
Applied to files:
stationapi/src/use_case/interactor/query.rs
🧬 Code graph analysis (1)
stationapi/src/use_case/interactor/query.rs (7)
stationapi/src/domain/entity/line.rs (1)
new(48-120)stationapi/src/domain/entity/train_type.rs (1)
new(26-58)stationapi/src/domain/entity/station.rs (1)
new(84-218)stationapi/src/domain/repository/line_repository.rs (5)
new(51-185)find_by_id(7-7)find_by_id(190-192)get_by_line_group_id(18-18)get_by_line_group_id(232-238)stationapi/src/infrastructure/company_repository.rs (3)
new(49-51)find_by_id_vec(56-60)find_by_id_vec(66-87)stationapi/src/domain/entity/company.rs (1)
new(21-49)stationapi/src/domain/repository/train_type_repository.rs (3)
new(42-97)get_by_line_group_id(7-8)get_by_line_group_id(102-113)
⏰ 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). (2)
- GitHub Check: Test Suite
- GitHub Check: Test Suite
🔇 Additional comments (6)
stationapi/src/use_case/interactor/query.rs (6)
239-257: HashMap による O(1) 検索への最適化は適切です。company_map、train_type_map、station_lookup の3つの HashMap を導入することで、後続の線形探索を O(1) 検索に置き換えています。参照を使用することでマップ構築時のクローンも回避されており、パフォーマンス改善として正しい実装です。
303-318: station_lookup の使用方法は適切です。複合キー
(line_cd, station_g_cd)を使用した HashMap 検索が正しく実装されており、取得したステーションの clone と enrichment 処理も適切に行われています。
612-621: 過去のレビューコメントで指摘された最適化が正しく実装されています。
tt_line_mapによる O(1) 検索への置き換えが適切に行われており、.copied()を使用することでより簡潔な実装になっています。以前の線形探索tt_lines.iter().find(...)からの改善として優れています。
823-840: train_type_by_type_cd マップを使った最適化は効果的です。事前にマップを構築することで、ループ内での繰り返し検索を回避しています。また、
seen_line_group_cdsによる重複排除ロジックも正しく実装されており、パフォーマンス向上に寄与しています。Also applies to: 878-880, 890-890
976-989: 近隣バス停のマップ化による最適化は適切です。
bus_stop_by_line_cdマップを使用することで、各路線に対する最も近いバス停の検索を効率化しています。重複排除のロジックも明確にコメントされており、実装として優れています。
999-1011: build_route_tree_map の参照ベースへの変更は優れた最適化です。
Vec<Station>からVec<&'a Station>への変更により、不要なクローンを回避しており、ライフタイム注釈'aも適切に設定されています。呼び出し元(lines 592, 696)は参照を正しく処理しており、ループ内で
stops.iter().filter_map(|row| row.line_group_cd...)のように参照のフィールドに直接アクセスしています。また、包括的なユニットテスト(lines 1444-1490)で参照の返却と処理が検証されており、メソッドは期待通りに動作しています。
本番環境で現状非公開のバス路線が紛れ込んでいた
Summary by CodeRabbit
新機能
変更点
改善
ドキュメント/テスト
✏️ Tip: You can customize this high-level summary in your review settings.