Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow pgstac parameters for geojsonsearch to be globally set in Settings #186

Merged
merged 4 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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