From c38698d251df62d6aae9ad9aa17cd433be564f07 Mon Sep 17 00:00:00 2001 From: Zoe Statman-Weil Date: Wed, 28 Aug 2024 13:40:29 -0700 Subject: [PATCH 1/4] move pgstac parameters to settings so can be globally set --- .env.example | 2 ++ titiler/pgstac/mosaic.py | 14 ++++++++------ titiler/pgstac/settings.py | 25 +++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/.env.example b/.env.example index 7b78282..ea47f13 100644 --- a/.env.example +++ b/.env.example @@ -23,3 +23,5 @@ MOSAIC_CONCURRENCY=1 DEBUG=TRUE TITILER_PGSTAC_API_DEBUG=TRUE + +TITILER_PGSTAC_BACKEND_ITEMS_LIMIT=200 diff --git a/titiler/pgstac/mosaic.py b/titiler/pgstac/mosaic.py index 3228c57..f4c2d97 100644 --- a/titiler/pgstac/mosaic.py +++ b/titiler/pgstac/mosaic.py @@ -1,6 +1,7 @@ """TiTiler.PgSTAC custom Mosaic Backend and Custom STACReader.""" import json +import os from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Type import attr @@ -26,10 +27,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, RetrySettings, PgstacSettings from titiler.pgstac.utils import retry cache_config = CacheSettings() +pgstac_config = PgstacSettings() retry_config = RetrySettings() @@ -273,11 +275,11 @@ 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..3400cd8 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_BACKEND_", + "env_file": ".env", + "extra": "ignore", + } + + class _RetrySettings(BaseSettings): """Retry settings""" From 65d4144ca788a22fdb0113460f404bcad1528f8b Mon Sep 17 00:00:00 2001 From: Zoe Statman-Weil Date: Wed, 28 Aug 2024 21:25:45 -0700 Subject: [PATCH 2/4] fix precommit issues --- titiler/pgstac/mosaic.py | 7 ++++--- titiler/pgstac/settings.py | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/titiler/pgstac/mosaic.py b/titiler/pgstac/mosaic.py index f4c2d97..3595dae 100644 --- a/titiler/pgstac/mosaic.py +++ b/titiler/pgstac/mosaic.py @@ -1,7 +1,6 @@ """TiTiler.PgSTAC custom Mosaic Backend and Custom STACReader.""" import json -import os from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Type import attr @@ -27,7 +26,7 @@ from rio_tiler.tasks import create_tasks, filter_tasks from rio_tiler.types import AssetInfo, BBox -from titiler.pgstac.settings import CacheSettings, RetrySettings, PgstacSettings +from titiler.pgstac.settings import CacheSettings, PgstacSettings, RetrySettings from titiler.pgstac.utils import retry cache_config = CacheSettings() @@ -278,7 +277,9 @@ def get_assets( 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 + 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: diff --git a/titiler/pgstac/settings.py b/titiler/pgstac/settings.py index 3400cd8..0f4055f 100644 --- a/titiler/pgstac/settings.py +++ b/titiler/pgstac/settings.py @@ -132,7 +132,7 @@ class PgstacSettings(BaseSettings): exitwhenfull: bool = True # Skip any items that would show up completely under the previous items - skipcovered:bool = True + skipcovered: bool = True model_config = { "env_prefix": "TITILER_PGSTAC_BACKEND_", From 71e60e61c7f2bdfca62133d861b524998c098a47 Mon Sep 17 00:00:00 2001 From: Zoe Statman-Weil Date: Thu, 29 Aug 2024 11:24:33 -0700 Subject: [PATCH 3/4] update to search instad of backent --- .env.example | 2 +- titiler/pgstac/settings.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.env.example b/.env.example index ea47f13..0a45b5b 100644 --- a/.env.example +++ b/.env.example @@ -24,4 +24,4 @@ DEBUG=TRUE TITILER_PGSTAC_API_DEBUG=TRUE -TITILER_PGSTAC_BACKEND_ITEMS_LIMIT=200 +TITILER_PGSTAC_SEARCH_ITEMS_LIMIT=200 diff --git a/titiler/pgstac/settings.py b/titiler/pgstac/settings.py index 0f4055f..bbec96f 100644 --- a/titiler/pgstac/settings.py +++ b/titiler/pgstac/settings.py @@ -135,7 +135,7 @@ class PgstacSettings(BaseSettings): skipcovered: bool = True model_config = { - "env_prefix": "TITILER_PGSTAC_BACKEND_", + "env_prefix": "TITILER_PGSTAC_SEARCH_", "env_file": ".env", "extra": "ignore", } From b175a2b0184191d92ea8a336df8955d185018038 Mon Sep 17 00:00:00 2001 From: Zoe Statman-Weil Date: Thu, 29 Aug 2024 11:28:18 -0700 Subject: [PATCH 4/4] rebase --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) 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)