Add random caching

This commit is contained in:
2022-04-02 16:56:34 +03:00
parent f1f320da9b
commit 2f6a4a192a
7 changed files with 86 additions and 14 deletions

View File

@@ -56,8 +56,12 @@ async def create_book(data: Union[CreateBook, CreateRemoteBook]):
@book_router.get("/random", response_model=BookDetail)
async def get_random_book(allowed_langs: frozenset[str] = Depends(get_allowed_langs)):
book_id = await GetRandomBookService.get_random_id(allowed_langs)
async def get_random_book(
request: Request, allowed_langs: frozenset[str] = Depends(get_allowed_langs)
):
book_id = await GetRandomBookService.get_random_id(
allowed_langs, request.app.state.redis
)
book = (
await BookDB.objects.select_related(SELECT_RELATED_FIELDS + ["sequences"])