Skip to content

feat(search): add record count RPC - #1962

Merged
akijakya merged 2 commits into
agntcy:mainfrom
Coooder-Crypto:feat/search-count-records
Aug 4, 2026
Merged

feat(search): add record count RPC#1962
akijakya merged 2 commits into
agntcy:mainfrom
Coooder-Crypto:feat/search-count-records

Conversation

@Coooder-Crypto

Copy link
Copy Markdown
Contributor

Summary

  • add a unary CountRecords RPC to SearchService
  • reuse the existing record query filters while counting distinct record CIDs
  • ignore pagination and sorting for total counts
  • regenerate the Go/gRPC API and add database and controller coverage

Motivation

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 lint
  • go test ./... in api
  • go test ./... in server
  • golangci-lint run --config ../.golangci.yml --new-from-rev=HEAD

Fixes #1939

@github-actions github-actions Bot added the size/S Denotes a PR that changes 50-199 lines label Aug 3, 2026
@Coooder-Crypto
Coooder-Crypto marked this pull request as ready for review August 3, 2026 08:56
@Coooder-Crypto
Coooder-Crypto requested a review from a team as a code owner August 3, 2026 08:56
@akijakya
akijakya requested a review from Copilot August 3, 2026 09:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 CountRecords to the Search DB API and implements distinct-record counting in the GORM database layer.
  • Exposes CountRecords on 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.

Comment thread server/controller/search.go

@akijakya akijakya left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sign off your commit please (and fix the lint error), otherwise LGTM, thanks for the contribution!

Signed-off-by: Coooder <1637120528@qq.com>
@Coooder-Crypto
Coooder-Crypto force-pushed the feat/search-count-records branch from d99dc47 to 6f4ad97 Compare August 3, 2026 12:59
@Coooder-Crypto

Copy link
Copy Markdown
Contributor Author

Sign off your commit please (and fix the lint error), otherwise LGTM, thanks for the contribution!

done 🚀

@codecov

codecov Bot commented Aug 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 33.33333% with 18 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
server/database/gorm/record.go 0.0% 18 Missing ⚠️

📢 Thoughts on this report? Let us know!

@akijakya
akijakya merged commit ca01a2b into agntcy:main Aug 4, 2026
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/S Denotes a PR that changes 50-199 lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SearchService: return total match count alongside paginated results

3 participants