Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(plugin-nested-docs): cannot update more than 10 child docs #10737

Merged
merged 1 commit into from
Jan 22, 2025

Conversation

DanRibbens
Copy link
Contributor

@DanRibbens DanRibbens commented Jan 22, 2025

limit was defaulting to 10 in the call to find children that need to be updated, now limit is 0 to get all children docs.

@r1tsuu
Copy link
Member

r1tsuu commented Jan 22, 2025

The async reduce function was not properly awaiting previous document saving #7788

I like for better anyway since it reduces callback overhead, but I don't think it wasn't properly awaiting, since it has await priorSave
I added some logging with your test to confirm it runs sequentially currently:

await children.docs.reduce(async (priorSave, child, i) => {
  await priorSave

  const childIsPublished =
    typeof collection.versions === 'object' &&
    collection.versions.drafts &&
    child._status === 'published'

  if (!parentDocIsPublished && childIsPublished) {
    return
  }

  console.log(`start ${i}`)
  await req.payload.update({
    id: child.id,
    collection: collection.slug,
    data: {
      ...child,
      [breadcrumbSlug]: await populateBreadcrumbs(req, pluginConfig, collection, child),
    },
    depth: 0,
    draft: !childIsPublished,
    locale: req.locale,
    req,
  })
  console.log(`end ${i}`)
}, Promise.resolve())
image

@DanRibbens
Copy link
Contributor Author

You are correct. I must have had my breakpoint in the wrong place.

@DanRibbens DanRibbens merged commit 3501d47 into main Jan 22, 2025
74 checks passed
@DanRibbens DanRibbens deleted the fix/plugin-nested-docs-limit branch January 22, 2025 22:42
Copy link
Contributor

🚀 This is included in version v3.19.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants