feat(matrix): 标签矩阵的博主名字左边显示粉丝数
取该博主最近一次**读到了数字**的账号快照。某一轮没解析出来(None)不让它把 之前的数字盖掉 —— 「这一轮没读到」不等于「这个号没有粉丝」。没有快照的博主 (作品模式刚导入还没跑过一轮)不画这个数字,而不是显示 0。
This commit is contained in:
@@ -256,6 +256,7 @@ async def _stat(
|
||||
nickname: str,
|
||||
captured_at: int | None = None,
|
||||
run_id: int = 1,
|
||||
fans: int | None = None,
|
||||
) -> None:
|
||||
async with monitor_db.get_session() as session:
|
||||
session.add(
|
||||
@@ -266,6 +267,7 @@ async def _stat(
|
||||
nickname=nickname,
|
||||
creator_id="",
|
||||
works_count=0,
|
||||
fans=fans,
|
||||
captured_at=captured_at or get_current_timestamp(),
|
||||
)
|
||||
)
|
||||
@@ -289,6 +291,40 @@ async def test_creators_without_notes_still_get_a_row(db):
|
||||
assert len(data["dates"]) == 7
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_the_creator_row_carries_the_latest_fan_count(db):
|
||||
"""博主列左边要显示的粉丝数 —— 取最近一次**读到了数字**的快照。
|
||||
|
||||
最新一轮如果是 None(没解析出来),不能让几千粉丝变成一个空白 ——
|
||||
「这一轮没读到」不等于「这个号没有粉丝」。
|
||||
"""
|
||||
task_id = await _task()
|
||||
now = get_current_timestamp()
|
||||
await _stat(task_id, "hash-a", "博主A", captured_at=now - 120_000, fans=1000, run_id=1)
|
||||
await _stat(task_id, "hash-a", "博主A", captured_at=now - 60_000, fans=1200, run_id=2)
|
||||
await _stat(task_id, "hash-a", "博主A", captured_at=now, fans=None, run_id=3)
|
||||
|
||||
async with monitor_db.get_session() as session:
|
||||
data = await service.daily_tag_matrix(session, "dy", days=7)
|
||||
|
||||
assert len(data["creators"]) == 1
|
||||
assert data["creators"][0]["name"] == "博主A"
|
||||
assert data["creators"][0]["fans"] == 1200
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_a_creator_without_a_snapshot_has_no_fan_count(db):
|
||||
"""作品模式刚导入、还没跑过一轮:粉丝数留 None,界面不画那个数字(不是 0)。"""
|
||||
task_id = await _task()
|
||||
now = get_current_timestamp()
|
||||
await _note(task_id, "n1", "只有作品", now - 1000)
|
||||
|
||||
async with monitor_db.get_session() as session:
|
||||
data = await service.daily_tag_matrix(session, "dy", days=7)
|
||||
|
||||
assert data["creators"][0]["fans"] is None
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_degraded_stat_snapshot_does_not_hide_the_name(db):
|
||||
"""资料接口偶尔回空对象(昵称/粉丝/作品数全空)。
|
||||
|
||||
Reference in New Issue
Block a user