Skip to content

Commit b090c10

Browse files
committed
perf: If the query result of the total number of lists is 0, it is directly returned
1 parent 476bc79 commit b090c10

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

fastapi_amis_admin/crud/_sqlalchemy.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -513,9 +513,9 @@ async def route(
513513
if data.filters:
514514
sel = sel.filter(*self.calc_filter_clause(data.filters))
515515
if paginator.show_total:
516-
data.total = await self.db.async_scalar(
517-
select(func.count("*")).select_from(sel.with_only_columns(self.pk).subquery())
518-
)
516+
data.total = await self.db.async_scalar(sel.with_only_columns(func.count("*")))
517+
if data.total == 0:
518+
return BaseApiOut(data=data)
519519
orderBy = self._calc_ordering(paginator.orderBy, paginator.orderDir)
520520
if orderBy:
521521
sel = sel.order_by(*orderBy)

0 commit comments

Comments
 (0)