Skip to content

Conversation

rjgtav
Copy link
Contributor

@rjgtav rjgtav commented Oct 10, 2025

What?

Adds the ability to inline relationships (i.e. use JOINs instead of separate SELECTs when fetching from the database).
This is controlled by a new inline flag that can be enabled when defining a relationship/upload field.
This feature works particularly well when used alongside the select parameter.

Why?

To reduce the total number of database queries that are generated when fetching, saving or updating collections. This is particularly impactful on collections with multiple relationship/upload fields. I've seen it reduce from 15-30 queries to the database in a single operation to just 5-10.

How?

By configuring Drizzle to join with the related collection, via the with parameter.

if ((isFieldLocalized || parentIsLocalized) && _locales) {
_locales.columns = _locales.columns || ({} as Result['columns'])
_locales.columns[fieldPath] = true
} else if (adapter.tables[currentTableName]?.[fieldPath]) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't use localization in my setup yet, so I'm not sure how correct this is.
I wrote it based on samples from other places in the file

if ((isFieldLocalized || parentIsLocalized) && _locales) {
_locales.with = _locales.with || {}
_locales.with[fieldPath] = true
} else {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't use localization in my setup yet, so I'm not sure how correct this is.
I wrote it based on samples from other places in the file

: { id: false, _parentID: false },
with: {},
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't use localization in my setup yet, so I'm not sure how correct this is.
I wrote it based on samples from other places in the file

Object.keys(withRelationship.with._locales.columns).length === 1
) {
delete withRelationship.with._locales
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't use localization in my setup yet, so I'm not sure how correct this is.
I wrote it based on samples from other places in the file

@rjgtav rjgtav changed the title perf(payload): added inline relationships (use JOINs instead of SELECTs) perf: added inline relationships (use JOINs instead of SELECTs) Oct 10, 2025
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.

1 participant