Skip to content

Query preview materializes up to 500 rows to display one integer #2743

Closed

Description

@malibio

Problem Statement

The query editor's Preview button answers "how many nodes match these filters?" by running the query and counting the rows:

// packages/desktop-app/src/lib/components/viewers/query-node-viewer.svelte
const nodes = await backendAdapter.executeQuery({
  targetType: definition.targetType,
  filters: definition.filters,
  limit: MAX_QUERY_ROWS,
});
return nodes.length;

For a type with many matches this fetches up to 500 full node payloads — content, properties, every column — transfers them over gRPC, deserializes them, and then calls .length on the array. Every byte past the count is discarded.

It also means the count saturates: the editor renders a full page as 500+ because that is the most it can distinguish. A user filtering 50,000 tasks down to 12,000 sees 500+, which is true but not useful for judging whether the filter is doing what they meant.

Prior art

CountNodes already exists for exactly this shape — it shares QueryNodesSimpleRequest with QueryNodesSimple and returns a scalar, with a comment noting it exists so callers need not transfer records they will not use. ExecuteQuery has no such counterpart.

Proposed Solution

Add a CountQuery RPC taking ExecuteQueryRequest (or its filter subset) and returning a count, mirroring the QueryNodesSimple/CountNodes pairing. QueryService would issue SELECT COUNT(*) against the same generated WHERE clause rather than selecting ids and hydrating nodes.

Then handleQueryPreview calls it instead, and the preview reports a real total with no ceiling.

Acceptance Criteria

  • A count RPC exists for the ExecuteQuery filter shape, reusing QueryService's WHERE-clause generation rather than duplicating it
  • handleQueryPreview uses it and no longer materializes rows
  • The preview reports an exact total with no 500+ saturation
  • Sorting is not requested for a count (it cannot affect one)

Context

Surfaced in review of #2742, which routed saved queries through QueryService. Deferred there as new backend capability rather than scope of that change.

Activity

  1. malibio commented on Sep 17, 2026

    @malibio
    CollaboratorAuthor

    Frontend baseline: 256 test files passed, 5214 tests passed (Duration 64.37s).

  2. self-assigned this
    on Sep 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions