-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PgSTAC: API hydration of search result items (#397)
* Upgrade to pgstac 0.5.1 Initial changes to get most tests passing. * Add option to hydrate pgstac search results in API * Support fields extension in nohydrate mode * Updates to hydrate and filter functionality. This was done in a pairing session with @mmcfarland * Fix fields extensions and reduce number of loops * Tolerate missing required attributes with fields extension Use of the fields extension can result in the return of invalid stac items if excludes is used on required attributes. When injecting item links, don't attempt to build links for which needed attributes aren't available. When API Hydrate is enabled, the required attributes are preserved prior to filtering and are used in the link generation. * Run pgstac tests in db and api hydrate mode * Merge dicts within lists during hydration In practice, an asset on a base_item and an item may have mergable dicts (ie, raster bands). * Add note on settings in readme * Pass request to base_item_cache This will be used by implementors who need app state which is stored on request. * Upgrade pypgstac and use included hydrate function The hydrate function was improved and moved to pypgstac so it could be used in other projects outside of stac-fastapi. It was developed with a corresponding dehydrate function to ensure parity between the two. The version of pypgstac is unpublished and pinned to a draft commit at the point and will be upgraded subsequently. * Improve fields extension implementation Correctly supports deeply nested property keys in both include and exclude, as well as improves variable naming, comments, and test cases. * Remove unused error type * adjust tests for changes in api * remove print statements * add bbox back to items in tests * Upgrade pgstac * Fix conformance test fixtures * Fix sqlalchemy test with new status for FK error * Align fields ext behavior for invalid includes * Lint * Changelog * Remove psycopg install dependency * Relax dependency version of pgstac to 0.6.* series * Update dev environment to pgstac 0.6.2 * Changelog fix Co-authored-by: Rob Emanuele <[email protected]> Co-authored-by: Ubuntu <planetarycomputer@pct-bitner-vm.kko0dpzi4g3udak2ovyb5nsdte.ax.internal.cloudapp.net>
- Loading branch information
1 parent
526501b
commit 162a1a2
Showing
16 changed files
with
975 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,16 +17,17 @@ | |
"buildpg", | ||
"brotli_asgi", | ||
"pygeofilter @ git+https://github.com/geopython/[email protected]#egg=pygeofilter", | ||
"pypgstac==0.6.*", | ||
] | ||
|
||
extra_reqs = { | ||
"dev": [ | ||
"pypgstac[psycopg]==0.6.*", | ||
"pytest", | ||
"pytest-cov", | ||
"pytest-asyncio>=0.17", | ||
"pre-commit", | ||
"requests", | ||
"pypgstac==0.4.5", | ||
"httpx", | ||
], | ||
"docs": ["mkdocs", "mkdocs-material", "pdocs"], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
stac_fastapi/pgstac/stac_fastapi/pgstac/types/base_item_cache.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
"""base_item_cache classes for pgstac fastapi.""" | ||
import abc | ||
from typing import Any, Callable, Coroutine, Dict | ||
|
||
from starlette.requests import Request | ||
|
||
|
||
class BaseItemCache(abc.ABC): | ||
""" | ||
A cache that returns a base item for a collection. | ||
If no base item is found in the cache, use the fetch_base_item function | ||
to fetch the base item from pgstac. | ||
""" | ||
|
||
def __init__( | ||
self, | ||
fetch_base_item: Callable[[str], Coroutine[Any, Any, Dict[str, Any]]], | ||
request: Request, | ||
): | ||
""" | ||
Initialize the base item cache. | ||
Args: | ||
fetch_base_item: A function that fetches the base item for a collection. | ||
request: The request object containing app state that may be used by caches. | ||
""" | ||
self._fetch_base_item = fetch_base_item | ||
self._request = request | ||
|
||
@abc.abstractmethod | ||
async def get(self, collection_id: str) -> Dict[str, Any]: | ||
"""Return the base item for the collection and cache by collection id.""" | ||
pass | ||
|
||
|
||
class DefaultBaseItemCache(BaseItemCache): | ||
"""Implementation of the BaseItemCache that holds base items in a dict.""" | ||
|
||
def __init__( | ||
self, | ||
fetch_base_item: Callable[[str], Coroutine[Any, Any, Dict[str, Any]]], | ||
request: Request, | ||
): | ||
"""Initialize the base item cache.""" | ||
self._base_items = {} | ||
super().__init__(fetch_base_item, request) | ||
|
||
async def get(self, collection_id: str): | ||
"""Return the base item for the collection and cache by collection id.""" | ||
if collection_id not in self._base_items: | ||
self._base_items[collection_id] = await self._fetch_base_item( | ||
collection_id, | ||
) | ||
return self._base_items[collection_id] |
Oops, something went wrong.