perf(douyu): 优化慢查询并修复供应商充值收口
This commit is contained in:
@@ -29,6 +29,7 @@ from web.backend.models import (
|
||||
AccountEvent,
|
||||
AccountLease,
|
||||
AuditLog,
|
||||
AutomationJob,
|
||||
DouyuExternalOrder,
|
||||
HuyaExternalOrder,
|
||||
PlatformFulfillmentTask,
|
||||
@@ -40,7 +41,7 @@ TESTS_DIR = Path(__file__).resolve().parent
|
||||
PROJECT_ROOT = TESTS_DIR.parent
|
||||
VERSIONS_DIR = PROJECT_ROOT / "web" / "backend" / "migrations" / "versions"
|
||||
|
||||
HEAD_REVISION = "20261120_0103"
|
||||
HEAD_REVISION = "20261121_0104"
|
||||
|
||||
# 迁移新增、但不声明在模型里的复合查询索引。
|
||||
EXTRA_INDEXES = (
|
||||
@@ -254,6 +255,65 @@ class TestMigrationSmoke:
|
||||
with admin_engine.begin() as conn:
|
||||
conn.execute(text(f"DROP DATABASE IF EXISTS `{mig_db}`;"))
|
||||
|
||||
def test_0104_enables_retention_and_adds_huya_status_index(self):
|
||||
creds = get_mysql_credentials()
|
||||
mig_db = f"douyu_login_mig_{secrets.token_hex(4)}"
|
||||
mig_url = (
|
||||
f"mysql+pymysql://{quote_plus(creds['user'])}:"
|
||||
f"{quote_plus(creds['password'])}@{creds['host']}:{creds['port']}/"
|
||||
f"{mig_db}?charset=utf8mb4"
|
||||
)
|
||||
admin_engine = get_test_engine()
|
||||
mig_engine = create_engine(mig_url)
|
||||
original_url = database_module.DATABASE_URL
|
||||
with admin_engine.begin() as conn:
|
||||
conn.execute(
|
||||
text(
|
||||
f"CREATE DATABASE `{mig_db}` "
|
||||
"CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;"
|
||||
)
|
||||
)
|
||||
try:
|
||||
database_module.DATABASE_URL = mig_url
|
||||
cfg = _migration_config()
|
||||
cfg.set_main_option("sqlalchemy.url", mig_url)
|
||||
command.upgrade(cfg, "20261120_0103")
|
||||
with Session(mig_engine) as session:
|
||||
session.add(
|
||||
AutomationJob(
|
||||
key="douyu_tasks_retention",
|
||||
title="任务日志清理",
|
||||
enabled=False,
|
||||
interval_seconds=24 * 3600,
|
||||
run_interval_seconds=300,
|
||||
batch_size=2000,
|
||||
concurrency=1,
|
||||
)
|
||||
)
|
||||
session.commit()
|
||||
|
||||
command.upgrade(cfg, "head")
|
||||
|
||||
with Session(mig_engine) as session:
|
||||
job = (
|
||||
session.query(AutomationJob)
|
||||
.filter(AutomationJob.key == "douyu_tasks_retention")
|
||||
.one()
|
||||
)
|
||||
assert job.enabled is True
|
||||
assert job.next_run_at is not None
|
||||
indexes = {
|
||||
row["name"]
|
||||
for row in inspect(mig_engine).get_indexes("huya_tasks")
|
||||
if row.get("name")
|
||||
}
|
||||
assert "ix_huya_tasks_account_status_id" in indexes
|
||||
finally:
|
||||
database_module.DATABASE_URL = original_url
|
||||
mig_engine.dispose()
|
||||
with admin_engine.begin() as conn:
|
||||
conn.execute(text(f"DROP DATABASE IF EXISTS `{mig_db}`;"))
|
||||
|
||||
def test_0077_converts_super_admin_membership_to_overlay(self):
|
||||
creds = get_mysql_credentials()
|
||||
mig_db = f"douyu_login_mig_{secrets.token_hex(4)}"
|
||||
|
||||
Reference in New Issue
Block a user