feat(search): add record count RPC - #1962
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new unary CountRecords RPC to SearchService so clients can retrieve the total number of matching records for paginated search views without streaming all results. This aligns SearchService with the existing catalog-side counting pattern (distinct record_cid, ignoring pagination/sorting).
Changes:
- Introduces
CountRecordsto the Search DB API and implements distinct-record counting in the GORM database layer. - Exposes
CountRecordson the gRPC SearchService (proto + regenerated Go stubs) and wires it into the server controller. - Adds database- and controller-level tests covering filtering, distinctness across joins, and error propagation.
Reviewed changes
Copilot reviewed 6 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| server/types/database.go | Extends SearchDatabaseAPI with a CountRecords method. |
| server/database/gorm/record.go | Implements CountRecords via COUNT(DISTINCT records.record_cid) with filters applied and pagination/sort ignored. |
| server/database/database_test.go | Adds DB tests for CountRecords behavior (filters, distinctness, ignores paging/sort, nil option). |
| server/controller/search.go | Adds unary CountRecords RPC handler that translates queries into DB filters and returns total_count. |
| server/controller/search_test.go | Adds controller tests for success, invalid query, and DB error propagation. |
| proto/agntcy/dir/search/v1/search_service.proto | Adds CountRecords RPC and request/response messages to the SearchService API. |
| api/search/v1/search_service.pb.go | Regenerated protobuf Go types for the new RPC/messages. |
| api/search/v1/search_service_grpc.pb.go | Regenerated gRPC client/server bindings including the new unary method. |
Files not reviewed (2)
- api/search/v1/search_service.pb.go: Generated file
- api/search/v1/search_service_grpc.pb.go: Generated file
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Coooder <1637120528@qq.com>
d99dc47 to
6f4ad97
Compare
done 🚀 |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Summary
CountRecordsRPC toSearchServiceMotivation
The streaming search APIs support pagination but do not expose the total number of matching records. Clients therefore cannot display total results or page counts without retrieving the full result set.
Validation
buf lintgo test ./...inapigo test ./...inservergolangci-lint run --config ../.golangci.yml --new-from-rev=HEADFixes #1939