Expose the record count on the on_query_change payload - #208
Merged
sevenseacat merged 1 commit intoAug 26, 2026
Conversation
Cinder already asks Ash for `count: true` on every load, for both offset
and keyset pagination, and renders the total in its own pagination footer.
A parent LiveView could not reach that number, so showing a total anywhere
else meant counting the same filter a second time.
Send the count Cinder already has alongside the query:
{event_name, %{query: query, count: 431, id: "users-table"}}
Paginated reads report whatever Ash returned, which may be nil if the read
produced no count. An unpaginated read reports the number of records it
loaded, which is the true total in that case.
Additive: existing handlers match on `query` and `id`, so a new key in the
payload map breaks no consumer.
Owner
|
I haven't figured out a nice way to automatically curate the changelog yet 😅 so for now yes, it's manually curated. I'll add an entry for this feature. Thank you so much for adding it! 🙌 ❤️ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Expose the record count on the
on_query_changepayloadWhy
A collection knows how many records match the current filters — it renders the
number in its own pagination footer. A parent LiveView cannot get at it. There
is no callback for it, and
pagelives on the LiveComponent's assigns.So an app that wants to show the total anywhere else — a page header, a summary
line, a tab label — has to count the filter a second time:
That is a full second
COUNTover the same filter, and it's redundant:QueryBuilder.execute/2already passescount: truefor both offset(
query_builder.ex:277) and keyset (:295) pagination, so Ash has computedthe number milliseconds earlier. The parent also has to dedupe the recount
itself, because
on_query_changefires on paging and sorting too, neither ofwhich can change a count.
What
on_query_changenow sendscountalongsidequery:The value is read off the page that was just loaded, so it costs nothing and
always agrees with the pagination footer — it lands in the same render as the
rows, with no second query and nothing for the parent to dedupe.
%Ash.Page.Offset{}/%Ash.Page.Keyset{}→ the count Ash returned, whichmay be
nilif the read produced none. This keeps working if counting everbecomes opt-out, as suggested in Feature request: Optional count with keyset pagination #154.
execute_without_pagination/2returns%{results: ...})→
length(results), which is the true total in that case since every matchingrecord was loaded.
nil.Compatibility
Additive. The payload is a map, and existing handlers match on
queryandid,so a new key breaks no consumer. Documented on both
<Cinder.collection>and<Cinder.Table.table>.Docs
docs/advanced.mdgains a short "Displaying the total elsewhere" subsection.usage-rules.mdhad noon_query_changeentry at all, so this adds a "QueryAccess" section covering the callback and the count. That is the file coding
agents read, and its silence here is what leads to generated code that runs a
second
Ash.count!over a query Cinder has already counted — which is exactlythe code this change removes. Happy to drop that hunk if you would rather keep
the PR to the payload alone.
No CHANGELOG entry — the Unreleased entries look maintainer-curated, with
attribution and PR links. Say the word and I will add one in whatever form you
prefer.
Tests
test/cinder/query_change_notification_test.exscovers the offset, keyset,nil-count, and unpaginated cases, that the query is still delivered alongsidethe count, and that nothing is sent when
on_query_changeis unset. Five of thesix fail without the change. Full suite green (1493 tests, 6 doctests).