From 8d115c798f2a5fd809443b4f618f5146b0bcab32 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Fri, 12 Aug 2022 12:26:01 -0700 Subject: web: remove remaining async endpoints with template rendering This makes all remaining HTML endpoints (which use jinja templates) synchronous, not async, meaning they render in a threadpool. This is a sanity change to reduce the chance of hard-to-debug concurrency issues with i18n and jinja2 templates. --- fatcat_scholar/web.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'fatcat_scholar') diff --git a/fatcat_scholar/web.py b/fatcat_scholar/web.py index 00a23d6..21855c0 100644 --- a/fatcat_scholar/web.py +++ b/fatcat_scholar/web.py @@ -91,7 +91,7 @@ api = APIRouter() @api.get("/", operation_id="get_home") -async def home() -> Any: +def home() -> Any: return {"endpoints": {"/": "this", "/search": "fulltext search"}} @@ -165,13 +165,13 @@ web = APIRouter() @web.get("/", include_in_schema=False) -async def web_home( +def web_home( request: Request, lang: LangPrefix = Depends(LangPrefix), content: ContentNegotiation = Depends(ContentNegotiation), ) -> Any: if content.mimetype == "application/json": - return await home() + return home() return i18n_templates(lang.code).TemplateResponse( "home.html", {"request": request, "locale": lang.code, "lang_prefix": lang.prefix}, @@ -179,7 +179,7 @@ async def web_home( @web.get("/about", include_in_schema=False) -async def web_about(request: Request, lang: LangPrefix = Depends(LangPrefix)) -> Any: +def web_about(request: Request, lang: LangPrefix = Depends(LangPrefix)) -> Any: return i18n_templates(lang.code).TemplateResponse( "about.html", {"request": request, "locale": lang.code, "lang_prefix": lang.prefix}, @@ -187,7 +187,7 @@ async def web_about(request: Request, lang: LangPrefix = Depends(LangPrefix)) -> @web.get("/help", include_in_schema=False) -async def web_help(request: Request, lang: LangPrefix = Depends(LangPrefix)) -> Any: +def web_help(request: Request, lang: LangPrefix = Depends(LangPrefix)) -> Any: return i18n_templates(lang.code).TemplateResponse( "help.html", {"request": request, "locale": lang.code, "lang_prefix": lang.prefix}, @@ -548,7 +548,7 @@ async def robots_txt(response_class: Any = PlainTextResponse) -> Any: @app.exception_handler(StarletteHTTPException) -async def http_exception_handler(request: Request, exc: StarletteHTTPException) -> Any: +def http_exception_handler(request: Request, exc: StarletteHTTPException) -> Any: """ This is the generic handler for things like 404 errors. """ -- cgit v1.2.3