perf(douyu): 限制任务并发并释放长事务连接
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
"""add douyu_tasks creator/scope/id index
|
||||
|
||||
普通用户的任务列表按 created_by + handbook_scope 过滤并按 id 倒序分页。
|
||||
已有 (created_by, id) 只能定位创建人,再向后扫描数百行才能凑够目标工作台
|
||||
的任务;新增三列复合索引后可以直接按目标范围倒序取页。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision: str = "20261120_0100"
|
||||
down_revision: str | None = "20261119_0099"
|
||||
branch_labels: str | None = None
|
||||
depends_on: str | None = None
|
||||
|
||||
INDEX_NAME = "ix_douyu_tasks_created_by_scope_id"
|
||||
|
||||
|
||||
def _indexes() -> set[str]:
|
||||
inspector = sa.inspect(op.get_bind())
|
||||
if not inspector.has_table("douyu_tasks"):
|
||||
return set()
|
||||
return {index["name"] for index in inspector.get_indexes("douyu_tasks")}
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
if INDEX_NAME not in _indexes():
|
||||
op.create_index(
|
||||
INDEX_NAME,
|
||||
"douyu_tasks",
|
||||
["created_by", "handbook_scope", "id"],
|
||||
unique=False,
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
if INDEX_NAME in _indexes():
|
||||
op.drop_index(INDEX_NAME, table_name="douyu_tasks")
|
||||
Reference in New Issue
Block a user