Skip to content

Commit

Permalink
perf: If the query result of the total number of lists is 0, it is di…
Browse files Browse the repository at this point in the history
…rectly returned
  • Loading branch information
amisadmin committed Dec 25, 2023
1 parent 476bc79 commit b090c10
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions fastapi_amis_admin/crud/_sqlalchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,9 +513,9 @@ async def route(
if data.filters:
sel = sel.filter(*self.calc_filter_clause(data.filters))
if paginator.show_total:
data.total = await self.db.async_scalar(
select(func.count("*")).select_from(sel.with_only_columns(self.pk).subquery())
)
data.total = await self.db.async_scalar(sel.with_only_columns(func.count("*")))
if data.total == 0:
return BaseApiOut(data=data)
orderBy = self._calc_ordering(paginator.orderBy, paginator.orderDir)
if orderBy:
sel = sel.order_by(*orderBy)
Expand Down

0 comments on commit b090c10

Please sign in to comment.