perf: optimize virtual fields that reference ID (#12159)

This PR optimizes the new virtual fields with relationships feature
https://github.com/payloadcms/payload/pull/11805 when the path
references the ID field, for example:
```
{
  name: 'postCategoryID',
  type: 'number',
  virtual: 'post.category.id',
},
```

Previously, we did additional population of `category`, which is
unnecessary as we can always grab the ID from the `category` value
itself. One less querying step.
This commit is contained in:
Sasha
2025-04-18 21:39:55 +03:00
committed by GitHub
parent df7a3692f7
commit fdff5871f6
4 changed files with 113 additions and 12 deletions

View File

@@ -373,8 +373,39 @@ export interface VirtualRelation {
id: string;
postTitle?: string | null;
postCategoryTitle?: string | null;
postCategoryID?:
| {
[k: string]: unknown;
}
| unknown[]
| string
| number
| boolean
| null;
postID?:
| {
[k: string]: unknown;
}
| unknown[]
| string
| number
| boolean
| null;
postLocalized?: string | null;
post?: (string | null) | Post;
customID?: (string | null) | CustomId;
customIDValue?: string | null;
updatedAt: string;
createdAt: string;
_status?: ('draft' | 'published') | null;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "custom-ids".
*/
export interface CustomId {
id: string;
title?: string | null;
updatedAt: string;
createdAt: string;
_status?: ('draft' | 'published') | null;
@@ -398,17 +429,6 @@ export interface FieldsPersistance {
updatedAt: string;
createdAt: string;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "custom-ids".
*/
export interface CustomId {
id: string;
title?: string | null;
updatedAt: string;
createdAt: string;
_status?: ('draft' | 'published') | null;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "fake-custom-ids".
@@ -807,8 +827,12 @@ export interface PlacesSelect<T extends boolean = true> {
export interface VirtualRelationsSelect<T extends boolean = true> {
postTitle?: T;
postCategoryTitle?: T;
postCategoryID?: T;
postID?: T;
postLocalized?: T;
post?: T;
customID?: T;
customIDValue?: T;
updatedAt?: T;
createdAt?: T;
_status?: T;