From fc6ebef14cf3398ac1664b9f585d6ed5e7caf609 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Mon, 29 Mar 2021 20:39:17 -0700 Subject: don't use async endpoints for sync implementations Embarassingly, I didn't know this was an option in FastAPI! Knew that running `await` on a function that was internally doing blocking calls was really bad, but didn't know the framework had such a simple way to avoid the problem. This significantly resolves operational concerns with the current service. --- fatcat_scholar/web.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'fatcat_scholar') diff --git a/fatcat_scholar/web.py b/fatcat_scholar/web.py index 9664474..005c22b 100644 --- a/fatcat_scholar/web.py +++ b/fatcat_scholar/web.py @@ -130,7 +130,7 @@ class HitsModel(BaseModel): @api.get("/search", operation_id="get_search", response_model=HitsModel) -async def search(query: FulltextQuery = Depends(FulltextQuery)) -> FulltextHits: +def search(query: FulltextQuery = Depends(FulltextQuery)) -> FulltextHits: hits: Optional[FulltextHits] = None if query.q is None: raise HTTPException(status_code=400, detail="Expected a 'q' query parameter") @@ -237,7 +237,7 @@ async def web_help(request: Request, lang: LangPrefix = Depends(LangPrefix)) -> @web.get("/search", include_in_schema=False) -async def web_search( +def web_search( request: Request, response: Response, query: FulltextQuery = Depends(FulltextQuery), @@ -246,7 +246,7 @@ async def web_search( ) -> Any: if content.mimetype == "application/json": - return await search(query) + return search(query) hits: Optional[FulltextHits] = None search_error: Optional[dict] = None status_code: int = 200 -- cgit v1.2.3