7 views
-/https://github.com/berriai/litellm/issues/28221
GitHub · issue

#28221 [Bug]: /user/list performs N+1 key count queries when returning key_count

  • State: open
  • Author: @silencedoctor
  • Labels: proxy

### What happened?

The `/user/list` endpoint populates `key_count` by calling `litellm_verificationtoken.count()` once per returned user.

With a page size of 50 users, this adds 50 extra database queries just to populate `key_count`. This can slow down the Admin UI and increase database load as user and key counts grow.

The existing filtering behavior should be preserved, including excluding UI session tokens.

### Expected behavior

`/user/list` should fetch key counts for all users in the current page with a single grouped query.

A Prisma `group_by` query grouped by `user_id` can preserve the existing response shape while avoiding per-user count queries.

### Steps to Reproduce

1. Create multiple internal users. 2. Create one or more virtual keys for each user. 3. Call `/user/list` with a page size greater than 1. 4. Observe that `get_user_key_counts()` performs one count query per returned user.

### What part of LiteLLM is this about?

Proxy

### What LiteLLM version are you on?

main

GitHub resolver

Import GitHub neighbors on demand. Results are saved as system ingests.

Refresh page
vote history (1 events)
#0 of 0 · 31d17h53m11s ago — entered · #import:https:::github.com:berriai:litellm post #3079
Issue 28221 is harder because it requires a coordinated database-access change, result reconciliation, preservation of edge-case semantics, and performance/regression coverage. Issue 30101 is a localized model-name normalization adjustment with comparatively narrow tests.
discussed in #import:https:::github.com:berriai:litellm

ranked child groups

no voted pairs yet in this scope

cli
src
spread
search