GetConnectedRoutesのメモリ負荷を削減 - #1616
Conversation
📝 WalkthroughWalkthrough連結経路探索は軽量な停車参照を使って探索し、候補確定後に必要な線区グループの駅詳細を一括取得する方式へ変更されました。リポジトリには専用の停車情報取得処理を追加しました。 Changes連結経路探索の遅延ロード
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant QueryInteractor
participant StationRepository
participant Database
QueryInteractor->>StationRepository: 軽量停車参照を取得
StationRepository->>Database: 連結経路パターン停車情報を検索
Database-->>StationRepository: 停車参照データ
StationRepository-->>QueryInteractor: ConnectedRoutePatternStop
QueryInteractor->>QueryInteractor: 軽量参照で経路候補を探索
QueryInteractor->>StationRepository: 候補の線区グループから駅詳細を取得
StationRepository-->>QueryInteractor: 完全な Station データ
QueryInteractor-->>QueryInteractor: 候補を駅詳細へ復元
Possibly related PRs
Suggested labels: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
stationapi/src/use_case/interactor/query.rs (1)
1428-1439: 🗄️ Data Integrity & Integration | 🔵 Trivial | 💤 Low value変数名のシャドーイングを解消してください。
query.rs:1428のdetailed_stopsをrestored_stopsなどへ変更し、query.rs:1409の変数と区別してください。🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@stationapi/src/use_case/interactor/query.rs` around lines 1428 - 1439, Rename the inner detailed_stops binding in the candidate restoration block to restored_stops (or an equivalent distinct name), and update its uses so it no longer shadows the detailed_stops variable near the earlier query logic. No direct change is required in stationapi/src/domain/repository/station_repository.rs:62-84.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@stationapi/src/use_case/interactor/query.rs`:
- Around line 1428-1439: Rename the inner detailed_stops binding in the
candidate restoration block to restored_stops (or an equivalent distinct name),
and update its uses so it no longer shadows the detailed_stops variable near the
earlier query logic. No direct change is required in
stationapi/src/domain/repository/station_repository.rs:62-84.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 80f1dcc1-f9f0-44a9-b67a-18ac813d3fa2
📒 Files selected for processing (5)
AGENTS.mddocs/architecture.mdstationapi/src/domain/repository/station_repository.rsstationapi/src/infrastructure/station_repository.rsstationapi/src/use_case/interactor/query.rs
概要
GetConnectedRoutesの探索時メモリ使用量とSQL負荷を削減します。原因
探索に必要なのは
line_group_cd、station_g_cd、passだけでしたが、各探索階層で駅名・住所・座標・路線属性・列車種別属性を含む完全なStationを取得していました。さらに、経路候補を展開するたびにVec<Station>を複製していたため、最大4,096状態の上限へ近づくとRaspberry PiでメモリとCPUを大きく消費していました。変更内容
line_group_cd、station_station_types.id、station_g_cd、passに限定Stationの生成を回避Vec<Station>を軽量参照へ置換Vec<Station>生成を廃止station_station_types.idで軽量駅列と詳細駅列を対応付け、alias JOIN等による行順の差に依存しないようにした影響
探索中のメモリ量が「探索状態数 × 完全なStation列」から「探索状態数 × 数値だけの軽量参照」になります。詳細なStationの生成は返却対象経路だけに限定されます。APIレスポンス形式と探索上限は変更しません。
検証
GitHub Actionsですべて成功:
cargo testcargo checkcargo clippy -- -D warningscargo fmt --all -- --check