plugin-nested-docs: option to re-save only children whose breadcrumbs would change, instead of the whole subtree on every publish
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
- Issue type
- Feature
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- typescript
Research direction
Read the nested-docs plugin's resaveChildren implementation and its getParents, populateBreadcrumbs, formatBreadcrumb, generateLabel, and generateURL paths, along with the referenced issues #14943 and #5706. Trace how published children and pending drafts are read and saved, then assess the proposed opt-in behavior against the Postgres reproduction; done means unrelated parent edits avoid descendant writes while breadcrumb changes still cascade correctly.
Written by the indexing model from the issue text.
Description
Describe the Bug
After every published save, resaveChildren re-saves every child (both its published version and its pending draft), and each re-saved child runs the same hook on its own children. This happens whatever changed. Publishing a change to an unrelated field on a page re-saves its whole subtree, one document after another, inside the parent's transaction.
The cost grows with subtree size, not with what was edited: every descendant gets a new version and runs its full hook and validation chain, all inside the parent's transaction, even when the edit can't affect any breadcrumb.
(This is about cost, not lost saves: publishes we saw fail under this cascade turned out to be #15515.)
Why the full cascade can't simply be dropped
Re-saving a child does more than refresh its breadcrumbs. It runs the child's own hooks and their side effects (revalidation, search indexing, webhooks, a hook that derives a field from the child's ancestors). Some projects may depend on an ancestor's save refreshing those. The plugin can't know, so the full cascade should stay the default.
Proposal: an opt-in, with an exact breadcrumb check
Something like resaveChildren: 'always' | 'whenBreadcrumbsChange' (or a shouldResaveChild({ child, expectedBreadcrumbs, req }) callback), default 'always'. With 'whenBreadcrumbsChange':
- Read the published parent and its ancestors once (
getParents), as the child's beforeChange hook would. - Read the children (both their published versions and pending drafts) in full.
- For each child, compute in memory the breadcrumbs
populateBreadcrumbswould write: for each document in[...ancestors, parent, child],formatBreadcrumbover the chain up to it, using the configuredgenerateLabel/generateURL. - Re-save only the children whose stored breadcrumbs (
docid,url,label) differ. Each re-saved child runs the hook in turn, so the cascade reaches exactly the part of the tree a change affects. - When a child's published version is re-saved, re-save its pending draft after it, so the draft stays the newest version (the #14943 situation).
Computing the expected breadcrumbs, rather than checking that a child's stored crumbs start with the parent's, matters. generateLabel / generateURL receive the whole chain, so a child's own crumb can depend on an ancestor field that ancestor's own crumb doesn't show. A prefix check would miss that. Comparing against the children's stored state, rather than diffing the parent against previousDoc the way #5706 does, also covers publishing a draft whose breadcrumbs changed, since draft saves never cascade.
With the option on, the only requirement is that generateLabel / generateURL depend only on their arguments. A save that changes nothing a breadcrumb depends on then does a few reads and no writes.
Given the core nested-docs work in #19277, will the core version avoid the full cascade, or offer something like this?
Reproduction Steps
- A collection with
versions.draftsandplugin-nested-docs, on a Postgres adapter. - Create a parent with a few dozen published descendants, several levels deep.
- Publish a change to any non-breadcrumb field on the parent (for example a checkbox).
- Every descendant gets a new version, and the save time grows with the size of the subtree.
Which area(s) are affected?
plugin: nested-docs
Environment Info
Reproduced on payload / @payloadcms/plugin-nested-docs 3.90.0.
- Dominant language
- TypeScript
- Stars
- 45.8k
- Forks
- 4.4k
- Avg merge
- 2d 16h
- Merged PRs (30d)
- 251
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from payloadcms/payload
-
db-d1-sqlite: upsert is aliased to updateOne, so payload.kv.set never inserts new keysPossibly taken @pcbeingused333 claimed this today. OpenBug db: d1-sqlite Payload OSS
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
payloadcms/payload#19766 ·
Maintainers usually reply within 1 day
-
Document bar (.doc-controls__content) overflows a 375 px viewport, clips "Created" and fails axe scrollable-region-focusablePossibly taken A pull request linked to this issue is open or already merged. Openarea: ui Bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
payloadcms/payload#19690 ·
Maintainers usually reply within 1 day
-
[v4] Blocks thumbnails croped 3:2Possibly taken @samiarif02 claimed this 2 days ago. Openarea: ui Bug Payload OSS status: needs-triage v3
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
payloadcms/payload#19609 ·
Maintainers usually reply within 1 day
-
Scheduled publish jobs are not deleted when their document is deleted (string id in the job, raw id in the cleanup)Possibly taken @volodymyrshk claimed this 10 days ago. Openarea: core Bug db: sqlite
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
payloadcms/payload#19448 ·
Maintainers usually reply within 1 day
-
plugin-multi-tenant: `isGlobal` collections redirect tenant-scoped users to `/admin` since 3.93.0 (GlobalViewRedirect prop-name mismatch)Possibly taken @JarrodMFlesch claimed this 10 days ago. OpenBug plugin: multi-tenant
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
payloadcms/payload#19420 · 1 assignee ·
Maintainers usually reply within 1 day
All issues in payloadcms/payload
Similar issues
-
`@angular/[email protected]` depends on vulnerable Vite 7.3.7 - GHSA-p4f5-76q4-ffq7 (Critical RCE)Openarea: @angular/build
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
angular/angular-cli#34764 ·
Maintainers usually reply within 1 day
-
status/need-triage
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
google-gemini/gemini-cli#30384 · 1 comment ·
Maintainers usually reply within 1 day
-
P2
Difficulty 1/5 Under an hour Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
bug ready-for-human
Difficulty 2/5 1-3 hours Newbie friendliness 60/100
LucasSantana-Dev/Lucky#3150 ·
Maintainers usually reply within 1 day
-
enhancement good first issue priority: low size: XS
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 1 day