feat(douyu): 查询工作台区分导入/查询数据、导入后自动查CK并修复登录刷新闪烁 (v0.4.29)
1) 闪烁修复:轮询(loadAccountsPage/loadManualBudget)改为静默模式, 不再每 2.2s 点亮表格 loading 遮罩与预算 Tag spinner;活动结束后保留 12s 宽限期继续静默刷新,避免登录刚完成就停刷导致行上残留「登录队列中」。 2) 导入后自动检测 CK:工作台 PUT 返回 imported_account_ids,前端分片 并发检测并显示进度,失效/无 CK 账号直接标红;/accounts/ck-check 对 无 CK、登录中的账号改为跳过(返回 checked/skipped)而不是整批报错。 行内新增「重登/人工登录该账号」入口,走既有人工登录预算。 3) 数据来源区分:douyu_workbench_accounts 新增 data_state/imported_at/ queried_at/relogin_at(迁移 20261130_0142)。导入标 imported,查询任务 成功由 _mark_task 标 queried,人工重登入队标 stale;PUT 工作台改为 upsert,不再整删整建以免重置状态。账号列表新增 workbench_scope/ workbench_state 入参与 workbench_* 回填字段。 4) 重登后只查重登账号:新增 /query-workbench/pending-ids(导入未查 + 重登待重查,仅含有可用 CK 者)与「只查待查询(N)」下拉;一键查询改为 尊重当前筛选(跨页),修正原来无视筛选直接查整台的问题。 5) CSV 末尾追加「数据来源 / 数据更新说明」两列,保持原有列序不变。
This commit is contained in:
@@ -565,6 +565,10 @@
|
||||
"20261129_0141_douyu_slow_query_indexes.py": {
|
||||
"revision": "20261129_0141",
|
||||
"sha256": "537ffb0a472c80d3a499c3c268aa62a2f5235ccc5399a81955a0e14d8721ea1f"
|
||||
},
|
||||
"20261130_0142_douyu_workbench_data_state.py": {
|
||||
"revision": "20261130_0142",
|
||||
"sha256": "eb2225861566f91a521edaf290ea29a638d173a833c49d41f3a7e0d9b629f4e6"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
"""查询工作台区分「导入后的数据」与「一键查询后的数据」
|
||||
|
||||
`douyu_workbench_accounts` 之前只记录「哪个账号在这个工作台里」,因此界面无法
|
||||
区分某一行是刚导入(只检测过 CK)还是已经跑过一键查询;重登成功后也没法只挑
|
||||
重新登录的账号再查一次。
|
||||
|
||||
新增四列:
|
||||
|
||||
- `data_state`:imported / queried / stale
|
||||
- `imported_at`:加入工作台的时间
|
||||
- `queried_at`:最近一次在本工作台查询成功的时间
|
||||
- `relogin_at`:最近一次发起人工重登的时间
|
||||
|
||||
Revision ID: 20261130_0142
|
||||
Revises: 20261129_0141
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision: str = "20261130_0142"
|
||||
down_revision: str | None = "20261129_0141"
|
||||
branch_labels: str | None = None
|
||||
depends_on: str | None = None
|
||||
|
||||
|
||||
def _has_column(inspector: sa.Inspector, table: str, column: str) -> bool:
|
||||
return any(col["name"] == column for col in inspector.get_columns(table))
|
||||
|
||||
|
||||
def _has_index(inspector: sa.Inspector, table: str, index_name: str) -> bool:
|
||||
return any(idx["name"] == index_name for idx in inspector.get_indexes(table))
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
bind = op.get_bind()
|
||||
inspector = sa.inspect(bind)
|
||||
table = "douyu_workbench_accounts"
|
||||
if not inspector.has_table(table):
|
||||
return
|
||||
|
||||
if not _has_column(inspector, table, "data_state"):
|
||||
op.add_column(
|
||||
table,
|
||||
sa.Column(
|
||||
"data_state",
|
||||
sa.String(length=16),
|
||||
nullable=False,
|
||||
server_default="imported",
|
||||
comment="imported/queried/stale:区分导入数据与一键查询数据",
|
||||
),
|
||||
)
|
||||
if not _has_column(inspector, table, "imported_at"):
|
||||
op.add_column(
|
||||
table,
|
||||
sa.Column("imported_at", sa.DateTime(), nullable=True, comment="导入工作台时间"),
|
||||
)
|
||||
if not _has_column(inspector, table, "queried_at"):
|
||||
op.add_column(
|
||||
table,
|
||||
sa.Column("queried_at", sa.DateTime(), nullable=True, comment="最近一次查询成功时间"),
|
||||
)
|
||||
if not _has_column(inspector, table, "relogin_at"):
|
||||
op.add_column(
|
||||
table,
|
||||
sa.Column("relogin_at", sa.DateTime(), nullable=True, comment="最近一次人工重登时间"),
|
||||
)
|
||||
|
||||
# 历史行:`created_at` 就是导入时间;已有 `overview_queried_at` 的账号视为已查询过。
|
||||
# 用 SQL 分批回填,避免 ORM 逐行加载。
|
||||
op.execute(
|
||||
sa.text(
|
||||
f"UPDATE {table} SET imported_at = created_at WHERE imported_at IS NULL"
|
||||
)
|
||||
)
|
||||
op.execute(
|
||||
sa.text(
|
||||
f"""
|
||||
UPDATE {table} AS w
|
||||
JOIN accounts AS a ON a.id = w.account_id
|
||||
SET w.data_state = 'queried', w.queried_at = a.overview_queried_at
|
||||
WHERE w.data_state = 'imported'
|
||||
AND a.overview_queried_at IS NOT NULL
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
inspector = sa.inspect(bind)
|
||||
if not _has_index(inspector, table, "ix_douyu_workbench_accounts_state"):
|
||||
op.create_index(
|
||||
"ix_douyu_workbench_accounts_state",
|
||||
table,
|
||||
["user_id", "handbook_scope", "data_state"],
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
bind = op.get_bind()
|
||||
inspector = sa.inspect(bind)
|
||||
table = "douyu_workbench_accounts"
|
||||
if not inspector.has_table(table):
|
||||
return
|
||||
if _has_index(inspector, table, "ix_douyu_workbench_accounts_state"):
|
||||
op.drop_index("ix_douyu_workbench_accounts_state", table_name=table)
|
||||
for column in ("relogin_at", "queried_at", "imported_at", "data_state"):
|
||||
if _has_column(inspector, table, column):
|
||||
op.drop_column(table, column)
|
||||
Reference in New Issue
Block a user