Skip to content

[6.x] Skip the terms lookup in listings when nothing is selected - #16169

Merged
jasonvarga merged 1 commit into
statamic:6.xfrom
SteveEdson:terms-skip-empty-lookups
Dec 4, 2026
Merged

jasonvarga merged 1 commit into
statamic:6.xfrom
SteveEdson:terms-skip-empty-lookups

Conversation

@SteveEdson

Copy link
Copy Markdown
Contributor

A terms field shown as a listing column runs a query for every row, including rows with nothing selected. The empty value becomes whereIn('slug', []), which can't match anything, but with the Eloquent driver it still goes to the database as where 0 = 1.

This PR returns an empty collection without building a query when nothing is selected, the same as #15879 did for the Entries fieldtype.

Measured with the Eloquent driver (v6.42.0)

A collection listing with six terms columns and 32 rows, where most rows leave some of those fields empty: 172 queries before, 79 after.

Tests

it_returns_an_empty_collection_when_preprocessing_index_and_nothing_is_selected counts queries with statamic.system.fake_sql_queries, the same way EntriesTest does. It fails without this change (2 queries for null and [], expected 0).

@jasonvarga
jasonvarga merged commit 47a4815 into statamic:6.x Dec 4, 2026
64 of 118 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants