We are using the versions feature with drafts enabled. We need to be able to determine the current version of a doc when retrieving it from the REST / GraphQL API. By default, it doesn't appear that payload explicitly stores any reference to the _versions index to tie a doc in a collection to it's current version.
We have initially tried to solve this with a afterRead hook that lists the versions for a doc, adding the latest version Id when returning it. This works, but has unfortunately had a significant negative impact on performance. When listing docs in a collection, the hook has to do a n+1 database query to get the version ID and hydrate the doc with it.
Is there a better way to do this? Ideally, we would love to have the versionId stored on a doc when the version is created. We can't quite figure out how to do this though. An afterRead hook is hydrating this after the fact but has bad performance. A beforeChange / beforeOperation hook doesn't seem like it would work because the version would not exist yet (?). Is there a performant way to store/retrieve the versionId of a document?