perf(douyu): 优化慢查询并修复供应商充值收口
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
"""启用任务日志清理并补虎牙任务状态索引。"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision = "20261121_0104"
|
||||
down_revision = "20261120_0103"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def _index_exists(table_name: str, index_name: str) -> bool:
|
||||
bind = op.get_bind()
|
||||
return bool(
|
||||
bind.execute(
|
||||
sa.text(
|
||||
"""
|
||||
SELECT COUNT(*)
|
||||
FROM information_schema.statistics
|
||||
WHERE table_schema = DATABASE()
|
||||
AND table_name = :table_name
|
||||
AND index_name = :index_name
|
||||
"""
|
||||
),
|
||||
{"table_name": table_name, "index_name": index_name},
|
||||
).scalar()
|
||||
)
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
if not _index_exists("huya_tasks", "ix_huya_tasks_account_status_id"):
|
||||
op.create_index(
|
||||
"ix_huya_tasks_account_status_id",
|
||||
"huya_tasks",
|
||||
["account_id", "status", "id"],
|
||||
unique=False,
|
||||
)
|
||||
op.execute(
|
||||
sa.text(
|
||||
"""
|
||||
UPDATE automation_jobs
|
||||
SET enabled = 1,
|
||||
next_run_at = COALESCE(next_run_at, UTC_TIMESTAMP()),
|
||||
updated_at = UTC_TIMESTAMP()
|
||||
WHERE `key` = 'douyu_tasks_retention'
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.execute(
|
||||
sa.text(
|
||||
"""
|
||||
UPDATE automation_jobs
|
||||
SET enabled = 0,
|
||||
next_run_at = NULL,
|
||||
updated_at = UTC_TIMESTAMP()
|
||||
WHERE `key` = 'douyu_tasks_retention'
|
||||
"""
|
||||
)
|
||||
)
|
||||
if _index_exists("huya_tasks", "ix_huya_tasks_account_status_id"):
|
||||
op.drop_index("ix_huya_tasks_account_status_id", table_name="huya_tasks")
|
||||
Reference in New Issue
Block a user