diff options
author | Bryan Newbold <bnewbold@archive.org> | 2022-08-12 12:26:01 -0700 |
---|---|---|
committer | Bryan Newbold <bnewbold@archive.org> | 2022-08-12 12:26:03 -0700 |
commit | 8d115c798f2a5fd809443b4f618f5146b0bcab32 (patch) | |
tree | 5dfd8bd09efdfdd58f6a2a456a31741d632eaeef | |
parent | 201681c6667a422936a7902ce8126f2e2aa336e8 (diff) | |
download | fatcat-scholar-8d115c798f2a5fd809443b4f618f5146b0bcab32.tar.gz fatcat-scholar-8d115c798f2a5fd809443b4f618f5146b0bcab32.zip |
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.
-rw-r--r-- | fatcat_scholar/web.py | 12 |
1 files changed, 6 insertions, 6 deletions
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. """ |