diff --git a/terraform/veda-wfs3/ecs_api.tf b/terraform/veda-wfs3/ecs_api.tf index a791f6e..1edbdfe 100644 --- a/terraform/veda-wfs3/ecs_api.tf +++ b/terraform/veda-wfs3/ecs_api.tf @@ -68,6 +68,10 @@ module "ecs_cluster" { // stupid hack b/c of FastAPI and Starlette bug name = "FAST_API_SCHEME" value = var.env == "west2-staging" ? "https" : "http" + }, + { + name = "TIPG_CATALOG_TTL" + value = "300" } ] diff --git a/veda-wfs3-app/fast_api_main.py b/veda-wfs3-app/fast_api_main.py index 4fb55b3..3adada4 100644 --- a/veda-wfs3-app/fast_api_main.py +++ b/veda-wfs3-app/fast_api_main.py @@ -13,7 +13,8 @@ from starlette.middleware.cors import CORSMiddleware from tipg.db import close_db_connection, connect_to_db, register_collection_catalog from tipg.factory import Endpoints as FeaturesEndpoints -from tipg.settings import PostgresSettings +from tipg.settings import PostgresSettings, APISettings, DatabaseSettings +from tipg.middleware import CatalogUpdateMiddleware from typing import Callable logger = logging.getLogger(__name__) @@ -91,6 +92,8 @@ async def dispatch(self, request, call_next): "postgres_port": db_config["port"], "postgres_dbname": db_config["dbname"] }) +api_settings = APISettings() +db_settings = DatabaseSettings() endpoints = FeaturesEndpoints(router=APIRouter(route_class=LoggerRouteHandler)) app.include_router(endpoints.router, tags=["OGC Features"]) @@ -103,6 +106,19 @@ async def dispatch(self, request, call_next): allow_methods=["GET", "POST", "OPTIONS"], allow_headers=["*"], ) +if api_settings.catalog_ttl: + app.add_middleware( + CatalogUpdateMiddleware, + ttl=api_settings.catalog_ttl, + schemas=db_settings.schemas, + tables=db_settings.tables, + exclude_tables=db_settings.exclude_tables, + exclude_table_schemas=db_settings.exclude_table_schemas, + functions=db_settings.functions, + exclude_functions=db_settings.exclude_functions, + exclude_function_schemas=db_settings.exclude_function_schemas, + spatial=db_settings.only_spatial_tables, + ) @app.on_event("startup")