Skip to content

fix: correct collection item search and reference loading#350

Merged
tristan-mouchet merged 1 commit into
developfrom
fix/collection-item-search-and-reference-loading
Jun 12, 2026
Merged

fix: correct collection item search and reference loading#350
tristan-mouchet merged 1 commit into
developfrom
fix/collection-item-search-and-reference-loading

Conversation

@tristan-mouchet

Copy link
Copy Markdown
Collaborator

Summary

Fixes two issues in collection item fetching: searching a collection's records could fail with a "Failed to count collection items" error, and reference-field text could fail to load on the canvas because some referenced collections received zero items.

Changes

  • Filter collection item search through an embedded inner join on collection_item_values instead of collecting matching item ids and using .in('id', ...). The values table has no collection_id, so the old approach matched values across every collection and built an id list large enough to overflow the request URL and fail the count query. The embedded join scopes matches to the collection via the parent FK.
  • Fix the top-items-per-collection fallback (used when the Postgres RPC is unavailable): a single shared query with a global limit let an early-sorting collection consume the whole row budget and starve later collections to zero rows, breaking reference-field lookups. Each collection's top N is now fetched independently.

Test plan

  • Search records in the dynamic page selector with short terms on a large collection — no "Failed to count collection items" error
  • Verify search results are scoped to the current collection only
  • Open a page binding dynamic text to a reference field — referenced values render on the canvas
  • Confirm reference fields across multiple collections all resolve (none starved to zero items)

Searching a collection's items matched values across every collection
(the values table has no collection_id), producing a huge id set that
overflowed the request URL and failed the count query. Filter through an
embedded inner join on collection_item_values instead, which scopes
matches to the collection via the parent FK and removes the id list.

Also fix the top-items-per-collection fallback: a single shared query
with a global limit let an early-sorting collection consume the whole
row budget and starve later collections to zero rows, breaking
reference-field lookups. Fetch each collection's top N independently.
@tristan-mouchet tristan-mouchet added the Bug Something isn't working label Jun 12, 2026
@tristan-mouchet tristan-mouchet self-assigned this Jun 12, 2026
@tristan-mouchet tristan-mouchet merged commit ab60404 into develop Jun 12, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant