docs(content): correct stale #1867 crash notes on live roll-ups (#84)#89
Merged
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
延续 #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.tssrc/objects/content_publication.object.ts(header docstring + 字段组注释)顺带:CHARTER flow 表过时
content CHARTER 的 flow 表仍把已下线的
publication_rollupflow 算进「五个 flow」。该 flow 在 totals 改成 summary 后就删了——现在实际是四个(build 输出4 Flows)。已更正。验证
全新 dev server 启动(@objectstack 15.1.1,seed 0 错误):
content_metric → content_publication:某 publicationtotal_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