Skip to content

Comments

Add relationship counts to list endpoint responses#22

Merged
awagner-mainz merged 5 commits intomainfrom
copilot/add-numbers-to-list-queries
Feb 13, 2026
Merged

Add relationship counts to list endpoint responses#22
awagner-mainz merged 5 commits intomainfrom
copilot/add-numbers-to-list-queries

Conversation

Copy link
Contributor

Copilot AI commented Feb 13, 2026

List endpoints returned minimal metadata without counts of related entities. Users needed multiple API calls to get basic relationship information (e.g., how many embeddings in a project, how many projects a user owns).

Changes

Database queries (5 new)

  • CountProjectsByUser, CountDefinitionsByUser, CountInstancesByDefinition
  • CountProjectsUsingInstance, CountSharedUsersForInstance
  • GetAllUsersWithCounts - optimized with LEFT JOINs, no N+1 queries

Models - added count fields:

  • ProjectBrief: number_of_embeddings
  • UserBrief: number_of_projects, number_of_definitions, number_of_instances (new model, replaces []string)
  • DefinitionBrief: number_of_instances
  • InstanceBrief: number_of_projects, number_of_shared_users

Handlers - populate counts in all list responses

Example

Before:

GET /v1/users
["alice", "bob"]

After:

GET /v1/users
[
  {
    "user_handle": "alice",
    "name": "Alice Smith",
    "number_of_projects": 3,
    "number_of_definitions": 1,
    "number_of_instances": 2
  }
]

Notes

Minor N+1 query patterns remain in projects/definitions/instances list endpoints but are acceptable given typical result set sizes. Users endpoint is fully optimized with single-query approach.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 4 commits February 13, 2026 17:14
…stances

- Added database count queries: CountProjectsByUser, CountDefinitionsByUser, CountInstancesByDefinition, CountProjectsUsingInstance, CountSharedUsersForInstance
- Added NumberOfEmbeddings to ProjectBrief model
- Created UserBrief model with counts (projects, definitions, instances) and updated GetUsersResponse to use it
- Added NumberOfInstances to DefinitionBrief model
- Added NumberOfProjects and NumberOfSharedUsers to InstanceBrief model
- Updated handlers to populate counts in list responses

Co-authored-by: awagner-mainz <2088443+awagner-mainz@users.noreply.github.com>
- Updated user tests to expect UserBrief with counts instead of just handles
- Updated project tests to expect ProjectBrief with number_of_embeddings
- Updated instance tests to expect InstanceBrief with number_of_projects and number_of_shared_users
- Updated pagination tests to handle new UserBrief response structure
- Updated public access tests with new InstanceBrief fields

Co-authored-by: awagner-mainz <2088443+awagner-mainz@users.noreply.github.com>
The API returns the user list as a direct array, not wrapped in an object.
Updated the pagination test to unmarshal correctly.

Co-authored-by: awagner-mainz <2088443+awagner-mainz@users.noreply.github.com>
Created GetAllUsersWithCounts query that retrieves all user information with counts
in a single efficient query using LEFT JOINs, eliminating the N+1 database query issue.

Co-authored-by: awagner-mainz <2088443+awagner-mainz@users.noreply.github.com>
Copilot AI changed the title [WIP] Add counts to list responses in API middleware Add relationship counts to list endpoint responses Feb 13, 2026
Copilot AI requested a review from awagner-mainz February 13, 2026 17:26
Copy link
Contributor

@awagner-mainz awagner-mainz left a comment

Choose a reason for hiding this comment

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

Looks good I think.

@awagner-mainz awagner-mainz marked this pull request as ready for review February 13, 2026 18:55
@awagner-mainz awagner-mainz merged commit 85ee3ec into main Feb 13, 2026
1 check passed
@awagner-mainz awagner-mainz deleted the copilot/add-numbers-to-list-queries branch February 13, 2026 18:55
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.

2 participants