mirror of
https://github.com/flibusta-apps/book_library_server.git
synced 2025-12-06 15:15:36 +01:00
Optimize
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
from typing import Optional, Generic, TypeVar, Union, cast
|
from typing import Optional, Generic, TypeVar, Union, cast
|
||||||
from itertools import permutations
|
from itertools import permutations
|
||||||
|
import asyncio
|
||||||
|
|
||||||
from fastapi_pagination.api import resolve_params
|
from fastapi_pagination.api import resolve_params
|
||||||
from fastapi_pagination.bases import AbstractParams, RawParams
|
from fastapi_pagination.bases import AbstractParams, RawParams
|
||||||
@@ -127,11 +128,16 @@ class TRGMSearchService(Generic[T]):
|
|||||||
async def get(cls, query: str) -> Page[T]:
|
async def get(cls, query: str) -> Page[T]:
|
||||||
params = cls.get_params()
|
params = cls.get_params()
|
||||||
|
|
||||||
authors = await cls.get_objects(query)
|
objects_task = asyncio.create_task(cls.get_objects(query))
|
||||||
total = await cls.get_objects_count(query)
|
total_task = asyncio.create_task(cls.get_objects_count(query))
|
||||||
|
|
||||||
|
await asyncio.wait({objects_task, total_task})
|
||||||
|
|
||||||
|
objects = objects_task.result()
|
||||||
|
total = total_task.result()
|
||||||
|
|
||||||
return CustomPage.create(
|
return CustomPage.create(
|
||||||
items=authors,
|
items=objects,
|
||||||
total=total,
|
total=total,
|
||||||
params=params
|
params=params
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user