perf(db): 增加查询索引并提升 redo log 容量

This commit is contained in:
yml
2026-11-20 22:26:10 +08:00
parent 409e22be90
commit 2eff8e1124
8 changed files with 100 additions and 33 deletions
+15
View File
@@ -8,6 +8,7 @@ from sqlalchemy import func, or_
from web.backend.models import Account, DouyuTask, User
from web.backend.routers.douyu import (
_split_task_scope_query,
_visible_tasks_query,
list_tasks,
)
@@ -184,6 +185,20 @@ def _seed_tasks(db):
return support, other, admin, no_scope_permission, tasks
def test_legacy_task_scope_uses_per_type_index_ranges(db):
branches = _split_task_scope_query(
db.query(DouyuTask.id),
"elite",
)
assert len(branches) == 1 + len(DOUYU_HANDBOOK_TASK_TYPES["elite"])
legacy_sql = [
str(branch.statement.compile(compile_kwargs={"literal_binds": True}))
for branch in branches[1:]
]
assert all("task_type = " in statement for statement in legacy_sql)
assert all(" IN (" not in statement for statement in legacy_sql)
def test_support_task_list_matches_legacy_semantics(db):
support, _, admin, no_scope_permission, tasks = _seed_tasks(db)
+1 -1
View File
@@ -40,7 +40,7 @@ TESTS_DIR = Path(__file__).resolve().parent
PROJECT_ROOT = TESTS_DIR.parent
VERSIONS_DIR = PROJECT_ROOT / "web" / "backend" / "migrations" / "versions"
HEAD_REVISION = "20261120_0101"
HEAD_REVISION = "20261120_0102"
# 迁移新增、但不声明在模型里的复合查询索引。
EXTRA_INDEXES = (