fix: batch key queries in list_team to eliminate N+1#23152
Merged
RheagalFire merged 2 commits intoBerriAI:litellm_oss_staging_03_11_2026from Mar 11, 2026
Merged
Conversation
The list_team endpoint issued one DB query per team to fetch keys, causing N+1 query overhead. Replace with a single batched IN query. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
Greptile SummaryThis PR fixes an N+1 database query problem in the Changes:
Correctness: The logic is straightforward and correct. The existing Scope: This PR successfully eliminates the N+1 query problem for the primary use case. No backwards-incompatible changes. Confidence Score: 5/5
Sequence DiagramsequenceDiagram
participant Client
participant list_team
participant DB as Database (Prisma)
Client->>list_team: GET /team/list
Note over list_team,DB: Before (N+1)
list_team->>DB: get teams (find_many)
DB-->>list_team: [team1, team2, ..., teamN]
loop for each team
list_team->>DB: find_many keys WHERE team_id = ?
DB-->>list_team: keys for team
end
Note over list_team,DB: After (batched)
list_team->>DB: get teams (find_many)
DB-->>list_team: [team1, team2, ..., teamN]
list_team->>DB: find_many keys WHERE team_id IN (id1, id2, ..., idN)
DB-->>list_team: all keys (single query)
list_team->>list_team: distribute keys in-memory by team_id
list_team-->>Client: TeamListResponseObject[]
Last reviewed commit: 37a46e6 |
This was referenced Mar 10, 2026
RheagalFire
requested changes
Mar 10, 2026
tests/test_litellm/proxy/management_endpoints/test_team_endpoints.py
Outdated
Show resolved
Hide resolved
tests/test_litellm/proxy/management_endpoints/test_team_endpoints.py
Outdated
Show resolved
Hide resolved
- Rename test to include "v1" for consistency with other test names - Remove unnecessary DB call assertion, keep behavioral assertions Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
c7e3b11
into
BerriAI:litellm_oss_staging_03_11_2026
21 of 37 checks passed
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.
Summary
list_teamendpoint issued onefind_manyquery per team to fetch verification token keys, causing an N+1 query problemINquery, then distribute keys in-memoryThe existing
@@index([team_id])onLiteLLM_VerificationTokenalready supports this query efficiently.Test plan
test_list_team_batches_key_queriesverifying:find_manyis called exactly once with anINquery (not once per team)🤖 Generated with Claude Code