-
Notifications
You must be signed in to change notification settings - Fork 111
PgSTAC: API hydration of search result items #397
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
Merged
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
efc6e64
Upgrade to pgstac 0.5.1
mmcfarland fed54e9
Add option to hydrate pgstac search results in API
mmcfarland d6d72c3
Support fields extension in nohydrate mode
mmcfarland f7a689c
Updates to hydrate and filter functionality.
lossyrob adb763d
Fix fields extensions and reduce number of loops
mmcfarland a45b095
Tolerate missing required attributes with fields extension
mmcfarland c86e0d9
Run pgstac tests in db and api hydrate mode
mmcfarland 78224da
Merge dicts within lists during hydration
mmcfarland e60fa7d
Add note on settings in readme
mmcfarland 7bda2ba
Pass request to base_item_cache
mmcfarland 35d7a12
Upgrade pypgstac and use included hydrate function
mmcfarland 951dd8f
Improve fields extension implementation
mmcfarland bf3acd5
Remove unused error type
mmcfarland 9be6586
adjust tests for changes in api
fe0a8a8
remove print statements
97e88d6
add bbox back to items in tests
50dc522
Merge pull request #1 from bitner/feature/hydrate
mmcfarland 7648261
Upgrade pgstac
mmcfarland 6d61492
Fix conformance test fixtures
mmcfarland 3f03f0b
Fix sqlalchemy test with new status for FK error
mmcfarland ff2fe86
Align fields ext behavior for invalid includes
mmcfarland 6ccd15e
Lint
mmcfarland 4358698
Changelog
mmcfarland 9a70a02
Remove psycopg install dependency
mmcfarland f6da7b1
Relax dependency version of pgstac to 0.6.* series
mmcfarland a9a3f5d
Update dev environment to pgstac 0.6.2
mmcfarland 88d6675
Changelog fix
mmcfarland File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.