feat: Admin token list server-side pagination + stats aggregation + model pool filtering#550
Open
hhhaiai wants to merge 5 commits into
Open
feat: Admin token list server-side pagination + stats aggregation + model pool filtering#550hhhaiai wants to merge 5 commits into
hhhaiai wants to merge 5 commits into
Conversation
Support filtering out specific account statuses (e.g. expired, disabled) from list results via a comma-separated exclude_statuses parameter. Applied across all three backends: SQLite, Redis, and SQL (MySQL/PostgreSQL).
Replace Python-side full table scan with efficient SQL aggregation for admin stats. SQLite uses json_extract(), MySQL/PostgreSQL use dialect-aware JSON functions. Reduces 120k stats query from timeout to ~900ms.
- GET /admin/api/tokens now supports page/page_size/pool/status/exclude_statuses query params with server-side filtering and pagination (max 2000/page) - New GET /admin/api/tokens/stats returns aggregated stats via get_stats() - Added fail_count to token serialization - Added timing logs for performance monitoring
- Replaced full-scan token loading with paginated API calls (max 2000/page) - Stats loaded separately via /tokens/stats endpoint - Status/pool filters use server-side filtering, NSFW filter client-side - All load() calls properly awaited for async consistency - Pagination controls with configurable page size
- _available_pools() now uses in-memory AccountRuntimeTable instead of repo.runtime_snapshot(), eliminating full DB scan on every request - WebUI /models endpoint applies same pool filtering as /v1/models - Added timing logs for model list performance monitoring
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
Admin 后台在 10 万+ 账号场景下页面无法加载,根因有三:
GET /admin/api/tokens全量扫描 — 原实现每页请求都遍历全部记录,12 万条数据直接超时GET /admin/api/tokens/statsPython 遍历 — 逐行反序列化 JSON 字段做聚合,O(n) 极慢_available_pools()调用runtime_snapshot()— 每次请求都从 DB 加载全量记录改动内容:
control/account/commands.pyListAccountsQuery新增exclude_statuses字段control/account/repository.pyget_stats()接口control/account/backends/local.pyexclude_statuses过滤 +get_stats()SQL 聚合(GROUP BY+json_extract)control/account/backends/redis.pyexclude_statuses过滤 +get_stats()scan 实现control/account/backends/sql.pyexclude_statuses过滤 +get_stats()聚合(dialect-aware JSON 提取)products/web/admin/tokens.pyGET /tokens改为服务端分页(page/page_size/pool/status/exclude_statuses),新增GET /tokens/stats端点products/web/webui/chat.py/models应用 pool 过滤,与/v1/models同步products/openai/router.py_available_pools()改用内存AccountRuntimeTable,不再调runtime_snapshot()statics/admin/account.htmlload()正确awaitTesting
本地 Docker 环境验证(122,091 条 SQLite 账号):
Related
关联 issue: #535