fix: database.py 懒初始化引擎 + list_files 返回真实 total

- database.py: engine/SessionLocal 改为延迟创建,避免 import 时副作用,
  并提供 dispose_engine() 支持配置热重载
- dao/uploaded_file_dao.py: 新增 count() 方法
- upload_service.py: list_files() 改用 dao.count() 返回数据库总条数,
  修复之前返回当前页条目数导致分页 total 语义错误的问题
This commit is contained in:
zikai
2026-06-24 07:42:30 +00:00
parent fda635ccbd
commit e5a725fc91
3 changed files with 48 additions and 14 deletions

View File

@@ -81,9 +81,10 @@ class UploadService:
# ---------------- 查询 ----------------
def list_files(self, limit: int = 100, offset: int = 0) -> tuple[int, list[UploadedFileOut]]:
total = self.dao.count()
rows = self.dao.list(limit=limit, offset=offset)
items = [UploadedFileOut.model_validate(r) for r in rows]
return len(items), items
return total, items
def get_out(self, file_id: int) -> UploadedFileOut | None:
row = self.dao.get_by_id(file_id)