Skip to content

Commit

Permalink
Merge pull request #186 from zstatmanweil/pgstac-settings
Browse files Browse the repository at this point in the history
Allow pgstac parameters for geojsonsearch to be globally set in Settings
  • Loading branch information
vincentsarago authored Aug 30, 2024
2 parents d353b9d + b175a2b commit c4a0915
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ MOSAIC_CONCURRENCY=1
DEBUG=TRUE

TITILER_PGSTAC_API_DEBUG=TRUE

TITILER_PGSTAC_SEARCH_ITEMS_LIMIT=200
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
15 changes: 9 additions & 6 deletions titiler/pgstac/mosaic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand Down Expand Up @@ -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:
Expand Down
25 changes: 25 additions & 0 deletions titiler/pgstac/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""

Expand Down

0 comments on commit c4a0915

Please sign in to comment.