## 概要 GTFS を含むデータ取り込みに **約7分半**かかっています。`main.rs` は起動時にこれを実行するため、再起動のたびに同じ時間がかかります。 全フィード(都営・西武・京王・東急バス)を `ODPT_ACCESS_TOKEN` 付きで取り込んだ際の実測です。 ``` GTFS import : 354.97 秒 GTFS integration : 72.64 秒 合計 : 約 7 分 30 秒 ``` ## 内訳 支配的なのは以下の3つでした。 | 処理 | 時間 | 場所 | |---|---|---| | `build_stop_route_mapping`(`WITH RECURSIVE canonical_shape`) | **63.1 秒** | `integrate_gtfs_to_stations` | | 東急バス ODPT JSON の変換(581,094 stop_times) | **約 95 秒** | `import_tokyu_odpt_data` | | 京王バス `stop_times` の取り込み | **41.9 秒** | `import_gtfs_stop_times` | | `stops_to_stations` | 3.8 秒 | | | `trip_variations_to_types` | 3.5 秒 | | | `crossreferences` | 1.8 秒 | | `build_stop_route_mapping` と `trip_variations_to_types` では sqlx が slow statement 警告を出しています。 ``` WARN sqlx::query: slow statement: execution time exceeded alert threshold summary="WITH RECURSIVE canonical_shape AS …" WARN sqlx::query: slow statement: execution time exceeded alert threshold summary="WITH per_variation AS ( …" ``` 単独で63秒かかる `build_stop_route_mapping` の再帰CTEが最も効きそうです。 ## 影響 **オンプレでは起動のたびにこれが走ります。** `main.rs` は起動時に `import_csv` → `import_gtfs` → `integrate_gtfs_to_stations` を実行する設計です。CSV 完了時点で health check は通るものの、その間バスデータは不完全な状態になります。 Cloudflare Workers 版 (#1635) では CI のビルド時に1回だけ走るため実行時レイテンシには影響しませんが、CI のジョブ時間が7分半増えます。 ## 参考: 取り込み後のデータ量 | テーブル | 鉄道のみ | 全フィード取り込み後 | |---|---|---| | lines | 624 | 1,601 (+977 バス路線) | | stations | 11,148 | 39,204 (+28,063 バス停) | | types | 325 | 1,585 (+1,260 バス系統) | | station_station_types | 43,677 | 65,281 | ## 環境 - PostgreSQL 18 (Docker, shared_buffers 等は既定値) - `ODPT_ACCESS_TOKEN` あり(全5フィード + 東急 ODPT JSON を取得) - release ビルド なお計測に使った PostgreSQL では `pg_trgm` 拡張が入っておらず、trigram インデックスの作成に失敗しています。本番環境ではインデックスがある分、一部のクエリはより速い可能性があります。
Activity