Add relationship counts to list endpoint responses#22
Merged
awagner-mainz merged 5 commits intomainfrom Feb 13, 2026
Merged
Conversation
…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
Contributor
awagner-mainz
left a comment
There was a problem hiding this comment.
Looks good I think.
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.
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,CountInstancesByDefinitionCountProjectsUsingInstance,CountSharedUsersForInstanceGetAllUsersWithCounts- optimized with LEFT JOINs, no N+1 queriesModels - added count fields:
ProjectBrief:number_of_embeddingsUserBrief:number_of_projects,number_of_definitions,number_of_instances(new model, replaces[]string)DefinitionBrief:number_of_instancesInstanceBrief:number_of_projects,number_of_shared_usersHandlers - populate counts in all list responses
Example
Before:
After:
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.