Skip to content

Commit 18557cc

Browse files
committed
avoid calling all_collections on landing page
1 parent 97e4cdb commit 18557cc

File tree

4 files changed

+85
-6
lines changed

4 files changed

+85
-6
lines changed

docker-compose.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ services:
1616
- azurite
1717
- redis
1818
command: >
19-
bash -c "pypgstac pgready && uvicorn pcstac.main:app --host 0.0.0.0 --port 8081 --reload --proxy-headers --root-path '/stac'"
19+
bash -c "pypgstac pgready && uvicorn pcstac.main:app --host 0.0.0.0 --port 8081 --reload --proxy-headers --root-path /stac"
2020
2121
tiler:
2222
image: pc-apis-tiler
@@ -86,6 +86,7 @@ services:
8686

8787
database:
8888
container_name: pc-stac-db
89+
platform: linux/amd64
8990
image: postgis/postgis:17-3.5
9091
environment:
9192
- POSTGRES_USER=username

pc-stac.dev.env

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
APP_ROOT_PATH=/stac
21
APP_HOST=0.0.0.0
32
APP_PORT=8081
43
FORWARDED_ALLOW_IPS=*

pcstac/pcstac/client.py

Lines changed: 82 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@
88
from fastapi import HTTPException, Request
99
from stac_fastapi.pgstac.core import CoreCrudClient
1010
from stac_fastapi.types.errors import NotFoundError
11+
from stac_fastapi.types.requests import get_base_url
1112
from stac_fastapi.types.stac import (
1213
Collection,
1314
Collections,
1415
Item,
1516
ItemCollection,
1617
LandingPage,
1718
)
19+
from stac_pydantic.links import Relations
20+
from stac_pydantic.shared import MimeTypes
1821

1922
from pccommon.config import get_all_render_configs, get_render_config
2023
from pccommon.config.collections import DefaultRenderConfig
@@ -238,11 +241,87 @@ async def _fetch() -> ItemCollection:
238241
return await cached_result(_fetch, cache_key, request)
239242

240243
async def landing_page(self, request: Request, **kwargs: Any) -> LandingPage:
241-
_super: CoreCrudClient = super()
244+
"""Landing page."""
242245

243246
async def _fetch() -> LandingPage:
244-
landing = await _super.landing_page(request=request, **kwargs)
245-
return landing
247+
"""Landing page.
248+
249+
NOTE: we need a custom landing page implementation
250+
to avoid the call to `all_collections` method.
251+
252+
TODO: replace this with:
253+
```
254+
_super: CoreCrudClient = super()
255+
256+
async def _fetch() -> LandingPage:
257+
landing = await _super.landing_page(request=request, **kwargs)
258+
return landing
259+
```
260+
when switching to stac-fastapi >=v5.1.
261+
262+
"""
263+
base_url = get_base_url(request)
264+
265+
landing_page = self._landing_page(
266+
base_url=base_url,
267+
conformance_classes=self.conformance_classes(),
268+
extension_schemas=[],
269+
)
270+
271+
# Add Queryables link
272+
if self.extension_is_enabled(
273+
"FilterExtension"
274+
) or self.extension_is_enabled("SearchFilterExtension"):
275+
landing_page["links"].append(
276+
{
277+
"rel": Relations.queryables.value,
278+
"type": MimeTypes.jsonschema.value,
279+
"title": "Queryables available for this Catalog",
280+
"href": urljoin(base_url, "queryables"),
281+
"method": "GET",
282+
}
283+
)
284+
285+
# Add Aggregation links
286+
if self.extension_is_enabled("AggregationExtension"):
287+
landing_page["links"].extend(
288+
[
289+
{
290+
"rel": "aggregate",
291+
"type": "application/json",
292+
"title": "Aggregate",
293+
"href": urljoin(base_url, "aggregate"),
294+
},
295+
{
296+
"rel": "aggregations",
297+
"type": "application/json",
298+
"title": "Aggregations",
299+
"href": urljoin(base_url, "aggregations"),
300+
},
301+
]
302+
)
303+
304+
# Add OpenAPI URL
305+
landing_page["links"].append(
306+
{
307+
"rel": Relations.service_desc.value,
308+
"type": MimeTypes.openapi.value,
309+
"title": "OpenAPI service description",
310+
"href": str(request.url_for("openapi")),
311+
}
312+
)
313+
314+
# Add human readable service-doc
315+
landing_page["links"].append(
316+
{
317+
"rel": Relations.service_doc.value,
318+
"type": MimeTypes.html.value,
319+
"title": "OpenAPI service documentation",
320+
"href": str(request.url_for("swagger_ui_html")),
321+
}
322+
)
323+
324+
return LandingPage(**landing_page)
246325

247326
return await cached_result(_fetch, CACHE_KEY_LANDING_PAGE, request)
248327

scripts/validate

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ geometry='{"type":"Polygon","coordinates":[[[-85.3125,30.9375],[-85.3125,31],[-8
1818
if [ "${BASH_SOURCE[0]}" = "${0}" ]; then
1919
scripts/setup
2020
which stac-api-validator >/dev/null || pip install stac-api-validator==0.6.7
21-
stac-api-validator --log-level DEBUG --root-url http://localhost:8080/stac/ \
21+
stac-api-validator --root-url http://localhost:8080/stac/ \
2222
--conformance collections \
2323
--conformance core \
2424
--collection naip \

0 commit comments

Comments
 (0)