Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gtfs-api: make cost limit configurable, increase to 3.000.000 #255

Merged
merged 2 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ IPL_GTFS_DB_POSTGRES_DB=gtfs_importer
IPL_GTFS_DB_POSTGRES_DB_PREFIX=gtfs

# gtfs-importer variables
IPL_GTFS_IMPORTER_IMAGE=ghcr.io/mobidata-bw/postgis-gtfs-importer:v4-2024-10-03T22.54.08-d81cfdd
IPL_GTFS_IMPORTER_IMAGE=ghcr.io/mobidata-bw/postgis-gtfs-importer:v4-2024-10-09T19.12.35-d771aa4
IPL_GTFS_IMPORTER_GTFS_DOWNLOAD_URL=https://www.nvbw.de/fileadmin/user_upload/service/open_data/fahrplandaten_mit_liniennetz/bwgesamt.zip
IPL_GTFS_IMPORTER_GTFS_DOWNLOAD_USER_AGENT=IPL (MobiData-BW)
# This assumes, that the ipl platform is started in a directory `ipl` which's name becomes
Expand All @@ -64,6 +64,9 @@ IPL_GTFS_IMPORTER_NETWORK=ipl_ipl
# Which schema to import into within each GTFS-dataset-specific PostgreSQL DB.
# Note: don't modify this without also adapting etc/gtfs/postprocessing.d/* accordingly.
IPL_GTFS_IMPORTER_SCHEMA=api
# Cost (as calculated by the PostgreSQL query planner) limit to all queries that can be made via gtfs-api.
# 3.000.000 is roughly equivalent to 0.5s-15s.
IPL_GTFS_API_COST_LIMIT=3000000

# `postgrest` role used by the gtfs-api service (PostgREST)
IPL_GTFS_DB_POSTGREST_USER=postgrest
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,7 @@ services:
GTFS_TMP_DIR: /var/gtfs
POSTGREST_USER: ${IPL_GTFS_DB_POSTGREST_USER:?missing/empty}
POSTGREST_PASSWORD: ${IPL_GTFS_DB_POSTGREST_PASSWORD:?missing/empty}
POSTGREST_STATEMENT_COST_LIMIT: ${IPL_GTFS_API_COST_LIMIT:?missing/empty}

gtfs-api-docs:
networks: [ipl]
Expand Down
5 changes: 4 additions & 1 deletion etc/gtfs/postprocessing.d/40-postgrest-cost-limit.sql
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,7 @@ SELECT pg_temp._alter_db(current_database(), 'session_preload_libraries', 'plan_
-- [3] https://github.com/PostgREST/postgrest/issues/3045

-- Limit postgrest's & web_anon's queries by the query planner's estimated cost.
ALTER ROLE postgrest SET plan_filter.statement_cost_limit = 1000000.0;
-- Use $POSTGREST_STATEMENT_COST_LIMIT, fall back to 1000000.
\set cost_limit `echo -n "${POSTGREST_STATEMENT_COST_LIMIT:1000000}"`
-- https://stackoverflow.com/a/18730455/1072129
ALTER ROLE postgrest SET plan_filter.statement_cost_limit = :'cost_limit';