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
+10 -2
View File
@@ -1532,10 +1532,11 @@ async def daily_tag_matrix(
# 标签一次取完,按 note_id 归组;顺序跟词表里的 sort_order 一致。
tags_by_note: Dict[str, List[str]] = {}
tag_order: Dict[str, int] = {}
if note_ids:
tag_rows = (
await session.execute(
select(MonitorNoteTag.note_id, MonitorTag.name)
select(MonitorNoteTag.note_id, MonitorTag.name, MonitorTag.sort_order)
.join(MonitorTag, MonitorTag.id == MonitorNoteTag.tag_id)
.where(
MonitorNoteTag.platform == platform,
@@ -1544,8 +1545,9 @@ async def daily_tag_matrix(
.order_by(MonitorTag.sort_order, MonitorTag.id)
)
).all()
for note_id, name in tag_rows:
for note_id, name, sort_order in tag_rows:
tags_by_note.setdefault(note_id, []).append(name)
tag_order.setdefault(name, sort_order)
# 指标:每篇作品取**最近一轮**(run_id 最大)。没有指标行的作品不参与求和 ——
# 未知和 0 是两回事,格子的提示里会显示成「—」而不是「0」。
@@ -1642,6 +1644,12 @@ async def daily_tag_matrix(
if value is not None:
bucket[key] = (bucket[key] or 0) + value
# 一个格子可能合并了多天里的多条作品、多个标签。统一按**词表顺序**排 ——
# 否则同样的数据,换个遍历顺序就换了标签顺序,看起来像数据变了。
for day_cells in cells.values():
for bucket in day_cells.values():
bucket["tags"].sort(key=lambda name: tag_order.get(name, 10**6))
creators = [{"hash": hash_, "name": name} for hash_, name in known.items()]
creators.sort(key=lambda item: item["name"])