fix(report): 格子里的标签并集按词表顺序排,不再取决于遍历顺序
Deploy VitePress site to Pages / build (push) Canceled after 0s
Deploy VitePress site to Pages / Deploy (push) Canceled after 0s

一个格子可能合并了同一天的多条作品。原先标签是「遍历到哪条就先放哪条的」——同一批
数据换个快照顺序,格子里的标签顺序就会变,看起来像数据变了。现在统一按
monitor_tag.sort_order 排,和图例写的一致。

新增用例钉住这个行为:同一天两条不同标签 → 合成一格(计数 2、标签并集、
顺序为 大字报·养号)。
This commit is contained in:
butubb
2026-10-22 14:19:00 +08:00
parent 15c52553d0
commit 36407cafc5
2 changed files with 35 additions and 2 deletions
+25
View File
@@ -162,6 +162,31 @@ async def test_same_day_notes_collapse_with_tags_union(db):
assert cell["tags"] == ["大字报", "养号"]
@pytest.mark.asyncio
async def test_two_notes_with_different_tags_merge_into_one_cell(db):
"""同一天两条不同标签:合成一格,计数相加,标签取并集。
注意并集**按词表顺序**排,不是按作品先后 —— 否则同样的数据换个遍历顺序就会
看起来不一样。代价是「哪个标签属于哪条视频」这个信息在这一格里没有了。
"""
task_id = await _task()
now = get_current_timestamp()
await _note(task_id, "older", "博主A", now - 2000)
await _note(task_id, "newer", "博主A", now - 1000)
dazibao = await _tag("大字报", 1)
yanghao = await _tag("养号", 2)
await _attach("dy", "older", dazibao)
await _attach("dy", "newer", yanghao)
async with monitor_db.get_session() as session:
data = await service.daily_tag_matrix(session, "dy", days=7)
cell = data["cells"][_day(now)]["hash-a"]
assert cell["count"] == 2
assert cell["tags"] == ["大字报", "养号"]
@pytest.mark.asyncio
async def test_dates_newest_first_and_creators_sorted(db):
task_id = await _task()