Add "Limit" QueryFilter to Etre queries#101
Merged
Conversation
There was a problem hiding this comment.
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: AddLimit int64toQueryFilter; client serializes it as a&limit=Nquery parameter when positive.api/api_gomux.go/es/es.go/es/config/config.go: Server-side parsing and validation of thelimitquery param; CLI flag--limitwith input validation.entity/store.go: Applies limit via MongoDB'sSetLimitfor regular queries and via post-fetch slicing for distinct queries (since MongoDB'sdistinctcommand 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.
zyin-squareup
approved these changes
Mar 10, 2026
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.
We can now pass a limit in QueryFilter (with
--limit Nin the CLI) to limit the number of rows returned. This works for distinct and non-distinct queries.