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

fix(server): multithreaded requests #843

Merged
merged 2 commits into from
Sep 25, 2023
Merged
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
57 changes: 20 additions & 37 deletions eodag/rest/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import traceback
from contextlib import asynccontextmanager
from distutils import dist
from json.decoder import JSONDecodeError
from typing import List, Optional, Union

import pkg_resources
Expand All @@ -36,6 +35,7 @@
from pydantic import BaseModel
from starlette.exceptions import HTTPException as StarletteHTTPException

from eodag.api.core import DEFAULT_ITEMS_PER_PAGE
from eodag.config import load_stac_api_config
from eodag.rest.utils import (
QueryableProperty,
Expand Down Expand Up @@ -308,7 +308,7 @@ class which describes the body of a search request
datetime: Union[str, None] = None
bbox: Union[list, str, None] = None
intersects: Union[dict, None] = None
limit: Union[int, None] = 20
limit: Union[int, None] = DEFAULT_ITEMS_PER_PAGE
page: Union[int, None] = 1
query: Union[dict, None] = None
ids: Union[List[str], None] = None
Expand Down Expand Up @@ -351,8 +351,7 @@ def collections(request: Request):
url = request.state.url
url_root = request.state.url_root

body = {}
arguments = dict(request.query_params, **body)
arguments = dict(request.query_params)
provider = arguments.pop("provider", None)

response = get_stac_collections(
Expand All @@ -371,8 +370,7 @@ def stac_collections_items(collection_id, request: Request):
url = request.state.url
url_root = request.state.url_root

body = {}
arguments = dict(request.query_params, **body)
arguments = dict(request.query_params)
provider = arguments.pop("provider", None)

response = search_stac_items(
Expand All @@ -392,8 +390,7 @@ def collection_by_id(collection_id, request: Request):
url = request.state.url_root + "/collections"
url_root = request.state.url_root

body = {}
arguments = dict(request.query_params, **body)
arguments = dict(request.query_params)
provider = arguments.pop("provider", None)

response = get_stac_collection_by_id(
Expand All @@ -407,14 +404,13 @@ def collection_by_id(collection_id, request: Request):


@router.get("/collections/{collection_id}/items/{item_id}", tags=["Data"])
async def stac_collections_item(collection_id, item_id, request: Request):
def stac_collections_item(collection_id, item_id, request: Request):
"""STAC collection item by id"""
logger.debug(f"URL: {request.url}")
url = request.state.url
url_root = request.state.url_root

body = {}
arguments = dict(request.query_params, **body)
arguments = dict(request.query_params)
provider = arguments.pop("provider", None)

response = get_stac_item_by_id(
Expand All @@ -441,8 +437,7 @@ def stac_collections_item_download(collection_id, item_id, request: Request):
"""STAC collection item local download"""
logger.debug(f"URL: {request.url}")

body = {}
arguments = dict(request.query_params, **body)
arguments = dict(request.query_params)
provider = arguments.pop("provider", None)

return download_stac_item_by_id_stream(
Expand All @@ -451,7 +446,7 @@ def stac_collections_item_download(collection_id, item_id, request: Request):


@router.get("/catalogs/{catalogs:path}/items", tags=["Data"])
async def stac_catalogs_items(catalogs, request: Request):
def stac_catalogs_items(catalogs, request: Request):
"""Fetch catalog's features
---
tags:
Expand Down Expand Up @@ -485,11 +480,8 @@ async def stac_catalogs_items(catalogs, request: Request):
logger.debug(f"URL: {request.url}")
url = request.state.url
url_root = request.state.url_root
try:
body = await request.json()
except JSONDecodeError:
body = {}
arguments = dict(request.query_params, **body)

arguments = dict(request.query_params)
provider = arguments.pop("provider", None)

catalogs = catalogs.strip("/").split("/")
Expand All @@ -505,7 +497,7 @@ async def stac_catalogs_items(catalogs, request: Request):


@router.get("/catalogs/{catalogs:path}/items/{item_id}", tags=["Data"])
async def stac_catalogs_item(catalogs, item_id, request: Request):
def stac_catalogs_item(catalogs, item_id, request: Request):
"""Fetch catalog's single features
---
tags:
Expand Down Expand Up @@ -542,11 +534,8 @@ async def stac_catalogs_item(catalogs, item_id, request: Request):
logger.debug(f"URL: {request.url}")
url = request.state.url
url_root = request.state.url_root
try:
body = await request.json()
except JSONDecodeError:
body = {}
arguments = dict(request.query_params, **body)

arguments = dict(request.query_params)
provider = arguments.pop("provider", None)

catalogs = catalogs.strip("/").split("/")
Expand All @@ -570,14 +559,11 @@ async def stac_catalogs_item(catalogs, item_id, request: Request):


@router.get("/catalogs/{catalogs:path}/items/{item_id}/download", tags=["Data"])
async def stac_catalogs_item_download(catalogs, item_id, request: Request):
def stac_catalogs_item_download(catalogs, item_id, request: Request):
"""STAC item local download"""
logger.debug(f"URL: {request.url}")
try:
body = await request.json()
except JSONDecodeError:
body = {}
arguments = dict(request.query_params, **body)

arguments = dict(request.query_params)
provider = arguments.pop("provider", None)

catalogs = catalogs.strip("/").split("/")
Expand All @@ -588,7 +574,7 @@ async def stac_catalogs_item_download(catalogs, item_id, request: Request):


@router.get("/catalogs/{catalogs:path}", tags=["Capabilities"])
async def stac_catalogs(catalogs, request: Request):
def stac_catalogs(catalogs, request: Request):
"""Describe the given catalog and list available sub-catalogs
---
tags:
Expand Down Expand Up @@ -616,11 +602,8 @@ async def stac_catalogs(catalogs, request: Request):
logger.debug(f"URL: {request.url}")
url = request.state.url
url_root = request.state.url_root
try:
body = await request.json()
except JSONDecodeError:
body = {}
arguments = dict(request.query_params, **body)

arguments = dict(request.query_params)
provider = arguments.pop("provider", None)

catalogs = catalogs.strip("/").split("/")
Expand Down