perf(platform): 按优先级分层查询账号候选池
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
"""账号池分层候选查询索引。
|
||||
|
||||
`live_candidate_accounts` 现在按 CK、生命周期、宝典状态和积分充足度分层查询;
|
||||
这条索引让每一层都能在过滤后直接按 CK 检查时间/积分/ID 取前 N 条。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision: str = "20261121_0109"
|
||||
down_revision: str | None = "20261121_0108"
|
||||
branch_labels: str | None = None
|
||||
depends_on: str | None = None
|
||||
|
||||
INDEX_NAME = "ix_accounts_pool_tier"
|
||||
|
||||
|
||||
def _index_exists(table: str, name: str) -> bool:
|
||||
conn = op.get_bind()
|
||||
return bool(
|
||||
conn.execute(
|
||||
sa.text(
|
||||
"SELECT COUNT(*) FROM information_schema.statistics "
|
||||
"WHERE table_schema = DATABASE() "
|
||||
"AND table_name = :table AND index_name = :name"
|
||||
),
|
||||
{"table": table, "name": name},
|
||||
).scalar()
|
||||
)
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
if not _index_exists("accounts", INDEX_NAME):
|
||||
op.create_index(
|
||||
INDEX_NAME,
|
||||
"accounts",
|
||||
[
|
||||
"auto_managed",
|
||||
"ck_check_status",
|
||||
"status",
|
||||
"elite_opened",
|
||||
"ck_checked_at",
|
||||
"points",
|
||||
"id",
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
if _index_exists("accounts", INDEX_NAME):
|
||||
op.drop_index(INDEX_NAME, table_name="accounts")
|
||||
Reference in New Issue
Block a user