Skip to content

docs(content): correct stale #1867 crash notes on live roll-ups (#84)#89

Merged
os-zhuang merged 1 commit into
mainfrom
claude/live-rollups-content
Jul 19, 2026
Merged

docs(content): correct stale #1867 crash notes on live roll-ups (#84)#89
os-zhuang merged 1 commit into
mainfrom
claude/live-rollups-content

Conversation

@os-zhuang

Copy link
Copy Markdown
Contributor

背景

延续 #84。content 模板的 total_* 汇总其实早已是原生 Field.summary——不需要转换:

  • content_publication.total_* = 对子表 content_metric 求和
  • content_piece.total_* = 对子表 content_publication.total_* 再求和(两级汇总)

引擎在子记录变化时服务端重算,两级链路都能正确级联(见下方 boot 实测)。

问题:过时的 #1867 崩溃注释

有三处注释仍用「hook 做不了 / 嵌套跨对象写入在 standalone QuickJS runtime 里崩溃」来解释为什么用 summary 字段。这在 framework#1867 修复后已不成立——hook 里的嵌套写入现在是安全的。

本 PR 把注释改成准确的理由:纯聚合(sum/max) 用声明式、delete-safe 的 summary 字段最合适(引擎在删除时会捕获子记录 FK 的 pre-image 重算;afterDelete 钩子只拿得到 { id }),而 非聚合 的跨对象 rollup 才该用嵌套写钩子。

  • src/hooks/index.ts
  • src/objects/content_publication.object.ts(header docstring + 字段组注释)

顺带:CHARTER flow 表过时

content CHARTER 的 flow 表仍把已下线的 publication_rollup flow 算进「五个 flow」。该 flow 在 totals 改成 summary 后就删了——现在实际是四个(build 输出 4 Flows)。已更正。

验证

全新 dev server 启动(@objectstack 15.1.1,seed 0 错误):

  • content_metric → content_publication:某 publication total_views 3720 / total_signups 45,与其 metric 行求和一致。
  • content_publication → content_piece:piece「Why we kept the demo gate…」total_views 11370(= 3720 + 7650,两条 publication)、total_signups 66(= 45 + 21)——两级汇总链实时生效。

影响

纯注释 / CHARTER 改动,无 schema、字段、逻辑变更。


Generated by Claude Code

…ion→piece roll-ups (#84)

content's `total_*` roll-ups on content_publication (sum of content_metric)
and content_piece (sum of content_publication) are already native
`Field.summary` fields — the engine recomputes them server-side and, as
boot-verified below, the two-level chain cascades correctly. No field
conversion is needed here.

What was stale: three notes still explained the summary-field choice by
claiming a hook "can't do it" because "nested cross-object writes crash /
are unsupported in the standalone QuickJS runtime". That is no longer true
(framework#1867 is fixed — nested writes from hooks are safe). Reframe the
notes to the accurate reason: a *pure aggregate* is best expressed as a
declarative, delete-safe `summary` field (the engine captures the child FK
pre-image on delete; an afterDelete hook only gets `{ id }`), while a hook
is the right tool for a *non-aggregate* cross-object rollup.

Also correct the content CHARTER flow table, which still listed a
`publication_rollup` flow among five shipping flows — that flow was retired
when the totals became summaries; the package ships four flows now (the
build confirms "4 Flows").

Boot-verified on a fresh dev server (@objectstack 15.1.1, 0 seed errors):
- content_metric → content_publication: e.g. a publication reports
  total_views 3720 / total_signups 45 summed from its metric rows.
- content_publication → content_piece: piece "Why we kept the demo gate…"
  reports total_views 11370 (= 3720 + 7650 of its two publications) and
  total_signups 66 (= 45 + 21) — the two-level summary chain is live.

Comment/CHARTER-only; no schema, field, or logic change.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BZguyAaQbyUpwMZ2gMLaAP
@os-zhuang
os-zhuang merged commit 2ae774f into main Jul 19, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants