fix(report): 空昵称的快照不再把好名字盖成「未知(hash)」
抖音资料接口偶尔会回一个空对象:nickname、sec_uid、fans、aweme_count 全空 (实测 2026-10-22 12:49 那一轮有两个号中招)。报表原先取「最新一条快照的昵称」, 空字符串把之前的好名字盖掉了,界面上就变成「未知(c873cb)」。 改成:**空昵称不算名字**,取「最近一条有名字的快照」;没有再退回作品里的 creator_name;都没有才显示「未知(hash 前 6 位)」。 注意这只修了展示。根因是采集端的资料读取会写进这种残缺快照 —— 它同时会让 粉丝数/作品数的曲线出现假的 0。那条要单独改 douyin_api.author_profile 的判空。 测试 14 条(新增:坏快照不遮盖旧名字、只有坏快照时退回作品里的名字)。
This commit is contained in:
@@ -250,17 +250,23 @@ async def test_no_tasks_returns_an_empty_shape(db):
|
||||
}
|
||||
|
||||
|
||||
async def _stat(task_id: int, creator_hash: str, nickname: str) -> None:
|
||||
async def _stat(
|
||||
task_id: int,
|
||||
creator_hash: str,
|
||||
nickname: str,
|
||||
captured_at: int | None = None,
|
||||
run_id: int = 1,
|
||||
) -> None:
|
||||
async with monitor_db.get_session() as session:
|
||||
session.add(
|
||||
MonitorCreatorStat(
|
||||
task_id=task_id,
|
||||
run_id=1,
|
||||
run_id=run_id,
|
||||
creator_hash=creator_hash,
|
||||
nickname=nickname,
|
||||
creator_id="",
|
||||
works_count=0,
|
||||
captured_at=get_current_timestamp(),
|
||||
captured_at=captured_at or get_current_timestamp(),
|
||||
)
|
||||
)
|
||||
|
||||
@@ -283,6 +289,37 @@ async def test_creators_without_notes_still_get_a_row(db):
|
||||
assert len(data["dates"]) == 7
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_degraded_stat_snapshot_does_not_hide_the_name(db):
|
||||
"""资料接口偶尔回空对象(昵称/粉丝/作品数全空)。
|
||||
|
||||
那一轮不能算「最新的名字」—— 否则一个空字符串会把之前的好名字盖掉,界面上
|
||||
变成「未知(hash)」。线上真有两个号这么丢过名字。
|
||||
"""
|
||||
task_id = await _task()
|
||||
now = get_current_timestamp()
|
||||
await _stat(task_id, "hash-a", "好名字", captured_at=now - 60_000, run_id=1)
|
||||
await _stat(task_id, "hash-a", "", captured_at=now, run_id=2) # 更新,但是坏的
|
||||
|
||||
async with monitor_db.get_session() as session:
|
||||
data = await service.daily_tag_matrix(session, "dy", days=7)
|
||||
|
||||
assert [c["name"] for c in data["creators"]] == ["好名字"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_empty_stat_falls_back_to_the_note_name(db):
|
||||
task_id = await _task()
|
||||
now = get_current_timestamp()
|
||||
await _note(task_id, "n1", "作品里的名字", now - 1000)
|
||||
await _stat(task_id, "hash-a", "")
|
||||
|
||||
async with monitor_db.get_session() as session:
|
||||
data = await service.daily_tag_matrix(session, "dy", days=7)
|
||||
|
||||
assert [c["name"] for c in data["creators"]] == ["作品里的名字"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_cell_sums_the_latest_metric_of_each_note(db):
|
||||
task_id = await _task()
|
||||
|
||||
Reference in New Issue
Block a user