diff --git a/.env.example b/.env.example index 7b78282..0a45b5b 100644 --- a/.env.example +++ b/.env.example @@ -23,3 +23,5 @@ MOSAIC_CONCURRENCY=1 DEBUG=TRUE TITILER_PGSTAC_API_DEBUG=TRUE + +TITILER_PGSTAC_SEARCH_ITEMS_LIMIT=200 diff --git a/CHANGES.md b/CHANGES.md index 951e2d1..d158200 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -3,6 +3,7 @@ ## Unreleased * add `cachecontrol_exclude_paths` attribute in `ApiSettings` to let users decide if some path should not have cache-control headers (defaults is to exclude `/list`) +* Add PgstacSettings such that the user can provide their own default settings for PgSTAC search ## 1.3.1 (2024-08-01) diff --git a/titiler/pgstac/mosaic.py b/titiler/pgstac/mosaic.py index 3228c57..3595dae 100644 --- a/titiler/pgstac/mosaic.py +++ b/titiler/pgstac/mosaic.py @@ -26,10 +26,11 @@ from rio_tiler.tasks import create_tasks, filter_tasks from rio_tiler.types import AssetInfo, BBox -from titiler.pgstac.settings import CacheSettings, RetrySettings +from titiler.pgstac.settings import CacheSettings, PgstacSettings, RetrySettings from titiler.pgstac.utils import retry cache_config = CacheSettings() +pgstac_config = PgstacSettings() retry_config = RetrySettings() @@ -273,11 +274,13 @@ def get_assets( "include": ["assets", "id", "bbox", "collection"], } - scan_limit = scan_limit or 10000 - items_limit = items_limit or 100 - time_limit = time_limit or 5 - exitwhenfull = True if exitwhenfull is None else exitwhenfull - skipcovered = True if skipcovered is None else skipcovered + scan_limit = scan_limit or pgstac_config.scan_limit + items_limit = items_limit or pgstac_config.items_limit + time_limit = time_limit or pgstac_config.time_limit + exitwhenfull = ( + pgstac_config.exitwhenfull if exitwhenfull is None else exitwhenfull + ) + skipcovered = pgstac_config.skipcovered if skipcovered is None else skipcovered with self.pool.connection() as conn: with conn.cursor() as cursor: diff --git a/titiler/pgstac/settings.py b/titiler/pgstac/settings.py index f819d0d..bbec96f 100644 --- a/titiler/pgstac/settings.py +++ b/titiler/pgstac/settings.py @@ -116,6 +116,31 @@ def check_enable(self): return self +class PgstacSettings(BaseSettings): + """Pgstac settings""" + + # Return as soon as we scan N items + scan_limit: int = 10000 + + # Return as soon as we have N items per geometru + items_limit: int = 100 + + # Return after N seconds to avoid long requests + time_limit: int = 5 + + # Return as soon as the geometry is fully covered + exitwhenfull: bool = True + + # Skip any items that would show up completely under the previous items + skipcovered: bool = True + + model_config = { + "env_prefix": "TITILER_PGSTAC_SEARCH_", + "env_file": ".env", + "extra": "ignore", + } + + class _RetrySettings(BaseSettings): """Retry settings"""