Skip to content

Commit c4a0915

Browse files
Merge pull request #186 from zstatmanweil/pgstac-settings
Allow pgstac parameters for geojsonsearch to be globally set in Settings
2 parents d353b9d + b175a2b commit c4a0915

File tree

4 files changed

+37
-6
lines changed

4 files changed

+37
-6
lines changed

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,5 @@ MOSAIC_CONCURRENCY=1
2323
DEBUG=TRUE
2424

2525
TITILER_PGSTAC_API_DEBUG=TRUE
26+
27+
TITILER_PGSTAC_SEARCH_ITEMS_LIMIT=200

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Unreleased
44

55
* 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`)
6+
* Add PgstacSettings such that the user can provide their own default settings for PgSTAC search
67

78
## 1.3.1 (2024-08-01)
89

titiler/pgstac/mosaic.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@
2626
from rio_tiler.tasks import create_tasks, filter_tasks
2727
from rio_tiler.types import AssetInfo, BBox
2828

29-
from titiler.pgstac.settings import CacheSettings, RetrySettings
29+
from titiler.pgstac.settings import CacheSettings, PgstacSettings, RetrySettings
3030
from titiler.pgstac.utils import retry
3131

3232
cache_config = CacheSettings()
33+
pgstac_config = PgstacSettings()
3334
retry_config = RetrySettings()
3435

3536

@@ -273,11 +274,13 @@ def get_assets(
273274
"include": ["assets", "id", "bbox", "collection"],
274275
}
275276

276-
scan_limit = scan_limit or 10000
277-
items_limit = items_limit or 100
278-
time_limit = time_limit or 5
279-
exitwhenfull = True if exitwhenfull is None else exitwhenfull
280-
skipcovered = True if skipcovered is None else skipcovered
277+
scan_limit = scan_limit or pgstac_config.scan_limit
278+
items_limit = items_limit or pgstac_config.items_limit
279+
time_limit = time_limit or pgstac_config.time_limit
280+
exitwhenfull = (
281+
pgstac_config.exitwhenfull if exitwhenfull is None else exitwhenfull
282+
)
283+
skipcovered = pgstac_config.skipcovered if skipcovered is None else skipcovered
281284

282285
with self.pool.connection() as conn:
283286
with conn.cursor() as cursor:

titiler/pgstac/settings.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,31 @@ def check_enable(self):
116116
return self
117117

118118

119+
class PgstacSettings(BaseSettings):
120+
"""Pgstac settings"""
121+
122+
# Return as soon as we scan N items
123+
scan_limit: int = 10000
124+
125+
# Return as soon as we have N items per geometru
126+
items_limit: int = 100
127+
128+
# Return after N seconds to avoid long requests
129+
time_limit: int = 5
130+
131+
# Return as soon as the geometry is fully covered
132+
exitwhenfull: bool = True
133+
134+
# Skip any items that would show up completely under the previous items
135+
skipcovered: bool = True
136+
137+
model_config = {
138+
"env_prefix": "TITILER_PGSTAC_SEARCH_",
139+
"env_file": ".env",
140+
"extra": "ignore",
141+
}
142+
143+
119144
class _RetrySettings(BaseSettings):
120145
"""Retry settings"""
121146

0 commit comments

Comments
 (0)