Skip to content

Add "Limit" QueryFilter to Etre queries#101

Merged
jemiahw merged 3 commits intomasterfrom
jemiah/count-limit
Mar 10, 2026
Merged

Add "Limit" QueryFilter to Etre queries#101
jemiahw merged 3 commits intomasterfrom
jemiah/count-limit

Conversation

@jemiahw
Copy link
Collaborator

@jemiahw jemiahw commented Mar 6, 2026

We can now pass a limit in QueryFilter (with --limit N in the CLI) to limit the number of rows returned. This works for distinct and non-distinct queries.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a Limit field to the etre.QueryFilter struct, allowing callers to cap the number of entities returned by a query. The limit is supported in both the CLI (--limit N) and the Go client, wires through the API server (validated as a non-negative integer), and is enforced in the data store for both regular and distinct queries.

Changes:

  • etre.go / entity_client.go: Add Limit int64 to QueryFilter; client serializes it as a &limit=N query parameter when positive.
  • api/api_gomux.go / es/es.go / es/config/config.go: Server-side parsing and validation of the limit query param; CLI flag --limit with input validation.
  • entity/store.go: Applies limit via MongoDB's SetLimit for regular queries and via post-fetch slicing for distinct queries (since MongoDB's distinct command doesn't natively support a limit).

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
etre.go Adds Limit int64 field to QueryFilter with a doc comment
entity_client.go Serializes Limit > 0 as &limit=N in query URL; imports strconv
api/api_gomux.go Parses and validates limit query parameter; rejects negative or non-numeric values with HTTP 400
entity/store.go Applies limit via SetLimit for cursor-based queries; slices result for distinct queries
es/es.go Validates --limit is non-negative before query; passes it through QueryFilter
es/config/config.go Adds Limit int64 option field and help text
client_test.go Tests that Limit > 0 is sent as query param and Limit == 0 is not
api/query_test.go Tests parsing of valid, zero, negative, and non-numeric limit values in the API handler
entity/store_test.go Tests limit behavior in StreamEntities for various combinations (zero, positive, over-limit, with labels, distinct)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@jemiahw jemiahw merged commit b6a89fc into master Mar 10, 2026
4 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.

3 participants