Skip to content

GetStationsByName RPCのパフォーマンス改善#1465

Merged
TinyKitten merged 3 commits intodevfrom
feature/get-stations-by-name-performance
Mar 25, 2026
Merged

GetStationsByName RPCのパフォーマンス改善#1465
TinyKitten merged 3 commits intodevfrom
feature/get-stations-by-name-performance

Conversation

@TinyKitten
Copy link
Member

@TinyKitten TinyKitten commented Mar 25, 2026

Summary

  • GetStationsByName の enrichment フェーズで skip_types_join=true に変更
  • line_group_id=None のため get_train_types_by_station_id_vec は常に空を返しており、station_station_types / types テーブルへの LEFT JOIN は完全に不要だった
  • 不要な JOIN の除去に加え、バス停クエリが逐次実行から tokio::try_join! による並列実行に変更される
  • GetStationsByLineGroupIdList (c079edb) と同じ最適化パターン

Test plan

  • cargo fmt --check 通過
  • cargo clippy 通過
  • cargo test 全380テスト通過
  • ステージング環境で GetStationsByName のレスポンスタイムを確認

🤖 Generated with Claude Code

Summary by CodeRabbit

リリースノート

  • Refactor
    • 駅検索の内部処理を変更し、特定の検索経路で重い結合処理を回避するようになりました(検索応答が軽量化)。
  • 改善
    • 「タイプ無し」検索結果で、利用可能な場合に路線グループ情報が正しく反映されるようになりました。

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions github-actions bot added the feature 要望対応や課題解決 label Mar 25, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 25, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: dfc0a8b3-183c-46fd-84d6-a84351364360

📥 Commits

Reviewing files that changed from the base of the PR and between 072a261 and 4b4eed2.

📒 Files selected for processing (1)
  • stationapi/src/use_case/interactor/query.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • stationapi/src/use_case/interactor/query.rs

📝 Walkthrough

Walkthrough

Query系エントリポイントでupdate_station_vec_with_attributes(..., skip_types_join)falsetrueに変更され、types用のJOINを使わないエンリッチ経路が選ばれるようになった。加えて、get_by_station_group_id_vec_no_typesline_group_cdstation_station_typesから取得されるようSQLが変更された。

Changes

Cohort / File(s) Summary
Query Enrichment Logic
stationapi/src/use_case/interactor/query.rs
複数のクエリ入口(find_station_by_id / get_stations_by_id_vec / get_stations_by_coordinates / get_stations_by_name)でupdate_station_vec_with_attributes(..., skip_types_join)falsetrueに変更。types用JOINをスキップするエンリッチ経路を利用するように切替。
Repository SQL Projection
stationapi/src/infrastructure/station_repository.rs
get_by_station_group_id_vec_no_typesline_group_cd出力を固定NULLから(SELECT ... FROM station_station_types ... )::intへ変更。該当station_cdに存在するline_group_cdを返すようにした。

Sequence Diagram(s)

sequenceDiagram
    participant Client as Client
    participant Interactor as QueryInteractor
    participant Repo as StationRepository
    participant DB as PostgreSQL

    Client->>Interactor: リクエスト (e.g. get_stations_by_name)
    Interactor->>Interactor: update_station_vec_with_attributes(..., skip_types_join=true)
    alt skip_types_join == true
        Interactor->>Repo: 基本駅データ取得 (no types path)
        Repo->>DB: SQL (no types projection with SELECT from station_station_types for line_group_cd)
        DB-->>Repo: rows with line_group_cd when present
        Repo-->>Interactor: station rows
        Interactor->>Interactor: enrich station/line/number/company (types JOINを実行しない)
    else skip_types_join == false
        Interactor->>Repo: データ取得 (types JOIN path)
        Repo->>DB: SQL including types JOIN
        DB-->>Repo: rows with types
        Repo-->>Interactor: station rows with types
        Interactor->>Interactor: full enrichment including types JOIN path
    end
    Interactor-->>Client: レスポンス
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Poem

🐰✨ 駅の道を軽やかに跳ぶよ
JOINの森は迂回して
でも線の印はちゃんと拾うよ
ぴょんと進めばレスポンス速く
うさぎは今日も走る!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% 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 PRのタイトル「GetStationsByName RPCのパフォーマンス改善」はメインの目的を明確に要約しており、実装内容(skip_types_joinの最適化、不要なJOINの削除)と一致しています。

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/get-stations-by-name-performance

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

@TinyKitten TinyKitten self-assigned this Mar 25, 2026
TinyKitten and others added 2 commits March 25, 2026 23:29
enrichmentフェーズでskip_types_join=trueに変更し、不要なstation_station_types/types
テーブルへのLEFT JOINを除去。バス停クエリも並列実行に変更。

_no_typesバリアントではline_group_cdをサブクエリで取得し、has_train_typesが
正しく設定されるよう対応。

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…esのパフォーマンス改善

line_group_id=None固定の3つのRPCでもskip_types_join=trueに変更し、
不要なstation_station_types/typesテーブルへのLEFT JOINを除去。

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@TinyKitten TinyKitten merged commit 6e26b6a into dev Mar 25, 2026
11 checks passed
@TinyKitten TinyKitten deleted the feature/get-stations-by-name-performance branch March 25, 2026 23:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature 要望対応や課題解決

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant