refactor(database): 优化数据库关联对象的载入 (#10)

This commit is contained in:
MingxuanGame
2025-07-31 20:11:22 +08:00
committed by GitHub
parent 1281e75bb1
commit be401e8885
13 changed files with 73 additions and 166 deletions

View File

@@ -28,19 +28,10 @@ async def get_users(
):
if user_ids:
searched_users = (
await session.exec(
select(User)
.options(*User.all_select_option())
.limit(50)
.where(col(User.id).in_(user_ids))
)
await session.exec(select(User).limit(50).where(col(User.id).in_(user_ids)))
).all()
else:
searched_users = (
await session.exec(
select(User).options(*User.all_select_option()).limit(50)
)
).all()
searched_users = (await session.exec(select(User).limit(50))).all()
return BatchUserResponse(
users=[
await UserResp.from_db(
@@ -63,9 +54,7 @@ async def get_user_info(
):
searched_user = (
await session.exec(
select(User)
.options(*User.all_select_option())
.where(
select(User).where(
User.id == int(user)
if user.isdigit()
else User.username == user.removeprefix("@")