You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(plugin-search): exclude skipped drafts in reindex handler (#14224)
<!--
Thank you for the PR! Please go through the checklist below and make
sure you've completed all the steps.
Please review the
[CONTRIBUTING.md](https://github.com/payloadcms/payload/blob/main/CONTRIBUTING.md)
document in this repository if you haven't already.
The following items will ensure that your PR is handled as smoothly as
possible:
- PR Title must follow conventional commits format. For example, `feat:
my new feature`, `fix(plugin-seo): my fix`.
- Minimal description explained as if explained to someone not
immediately familiar with the code.
- Provide before/after screenshots or code diffs if applicable.
- Link any related issues/discussions from GitHub or Discord.
- Add review comments if necessary to explain to the reviewer the logic
behind a change
### What?
### Why?
### How?
Fixes #
-->
### What?
This PR aims to provide better insight into how many documents were
reindexed. Currently, the reindex handler will ignore document status
and claim all documents were reindexed even when none were due to being
drafts (as per plugin-search default behavior).
This PR takes into consideration `syncDrafts` enabled in the plugin
config and whether the collection of the document being reindexed has
`drafts` enabled. In this way, we can "skip" attempting to reindex
documents that are drafts when syncDrafts is not true _and_ provide a
useful count for the end-user of how many draft docs were skipped during
reindexing.
### Why?
To provide more insight into how many documents/drafts were reindexed,
as well as provide a minor perf improvement when reindexing collections
with `syncDrafts: false`.
### How?
- By tracking document count in collections with drafts enabled via
`totalDocsWithDrafts`.
- Filtering the find in `reindexCollection` based on if `drafts` &
`syncDrafts` are enabled
Before:
[Search-Results---Payload--before.webm](https://github.com/user-attachments/assets/bfd7696d-1124-4df5-8f99-d86c282f485c)
After:
[Search-Results---Payload.webm](https://github.com/user-attachments/assets/7b0d5c84-328e-43e9-b0ae-5bcd0a0e9f07)
0 commit comments