mirror of
https://gh-proxy.org/https://github.com/klinsmaya/SQLBot.git
synced 2026-11-08 01:06:59 +08:00
perf: User and Workspace Sorting Optimization
This commit is contained in:
committed by
fit2cloud-chenyw
parent
73778c67c6
commit
460e7f605c
@@ -1,7 +1,7 @@
|
||||
from collections import defaultdict
|
||||
from typing import Optional
|
||||
from fastapi import APIRouter, HTTPException, Query
|
||||
from sqlmodel import SQLModel, func, or_, select, delete as sqlmodel_delete
|
||||
from fastapi import APIRouter, Query
|
||||
from sqlmodel import SQLModel, or_, select, delete as sqlmodel_delete
|
||||
from apps.system.crud.user import check_account_exists, check_email_exists, check_email_format, check_pwd_format, get_db_user, single_delete, user_ws_options
|
||||
from apps.system.models.system_model import UserWsModel, WorkspaceModel
|
||||
from apps.system.models.user import UserModel
|
||||
@@ -38,7 +38,14 @@ async def pager(
|
||||
paginator = Paginator(session)
|
||||
filters = {}
|
||||
|
||||
origin_stmt = select(UserModel.id).join(UserWsModel, UserModel.id == UserWsModel.uid, isouter=True).where(UserModel.id != 1).distinct()
|
||||
origin_stmt = (
|
||||
select(UserModel.id, UserModel.account)
|
||||
.join(UserWsModel, UserModel.id == UserWsModel.uid, isouter=True)
|
||||
.where(UserModel.id != 1)
|
||||
.distinct()
|
||||
.order_by(UserModel.account)
|
||||
)
|
||||
|
||||
if oidlist:
|
||||
origin_stmt = origin_stmt.where(UserWsModel.oid.in_(oidlist))
|
||||
if status is not None:
|
||||
|
||||
@@ -171,10 +171,11 @@ async def delete(session: SessionDep, current_user: CurrentUser, trans: Trans, d
|
||||
|
||||
@router.get("", response_model=list[WorkspaceModel])
|
||||
async def query(session: SessionDep, trans: Trans):
|
||||
list_result = session.exec(select(WorkspaceModel).order_by(WorkspaceModel.create_time.asc())).all()
|
||||
list_result = session.exec(select(WorkspaceModel)).all()
|
||||
for ws in list_result:
|
||||
if ws.name.startswith('i18n'):
|
||||
ws.name = trans(ws.name)
|
||||
ws.name = trans(ws.name)
|
||||
list_result.sort(key=lambda x: x.name)
|
||||
return list_result
|
||||
|
||||
@router.post("")
|
||||
|
||||
@@ -56,10 +56,13 @@ async def user_ws_options(session: Session, uid: int, trans: Optional[I18n] = No
|
||||
result = session.exec(stmt)
|
||||
if not trans:
|
||||
return result.all()
|
||||
return [
|
||||
list_result = [
|
||||
UserWs(id = id, name = trans(name) if name.startswith('i18n') else name)
|
||||
for id, name in result.all()
|
||||
]
|
||||
if list_result:
|
||||
list_result.sort(key=lambda x: x.name)
|
||||
return list_result
|
||||
|
||||
@clear_cache(namespace=CacheNamespace.AUTH_INFO, cacheName=CacheName.USER_INFO, keyExpression="id")
|
||||
async def single_delete(session: SessionDep, id: int):
|
||||
|
||||
Reference in New Issue
Block a user