Skip to content

feat: add top users consumption ranking to dashboard - #1

Merged
gmij merged 4 commits into
mainfrom
claude/adjust-user-display-name-and-dropdown
Mar 13, 2026
Merged

gmij merged 4 commits into
mainfrom
claude/adjust-user-display-name-and-dropdown

Conversation

@Claude

@Claude Claude AI commented Mar 13, 2026 •

Copy link
Copy Markdown

PR 类型

  • Bug 修复
  • 新功能
  • 文档更新
  • 其他

PR 是否包含破坏性更新?

  • 是
  • 否

PR 描述

Adds admin-only "用户消耗排行" (User Consumption Ranking) chart to the data dashboard showing top 10 highest consuming users by quota in descending order.

Backend Changes

  • New API endpoint: GET /api/data/top-users (admin-only, configurable limit default 10, max 100)
  • Database query: GetTopUsersByQuota() queries quota_data table, groups by user_id/username, sums quota, orders DESC
  • Uses existing quota_data aggregation infrastructure for efficient statistics

Frontend Changes

  • New chart: Horizontal bar chart (spec_user_rank_bar) with quota formatting via renderQuota()
  • 5th dashboard tab: "用户消耗排行" (admin-only visibility using isAdminUser check)
  • Data flow: loadTopUsersData() API call integrated into dashboard refresh cycle
  • i18n: Added English translations for "用户消耗排行" → "User consumption ranking" and "个用户" → " users"

Implementation Notes

The feature correctly uses quota_data (pre-aggregated hourly statistics) rather than the logs table for efficient aggregation. Chart updates reactively when time range changes or data refreshes.

- Add display_name field to Log model (read-only from users table)
- Update GetAllLogs to fetch display_name via bulk query
- Update frontend to show display_name instead of username
- Add grouping dropdown with User/Hour/Model options
- Implement grouping logic with aggregated stats

Co-authored-by: gmij <22893579+gmij@users.noreply.github.com>
@Claude Claude AI changed the title [WIP] Update user list to show display names and add grouping dropdown feat: display user display_name in logs and add grouping dropdown Mar 13, 2026
@Claude
Claude AI requested a review from gmij March 13, 2026 10:06
The grouping feature was querying the logs table and doing client-side
aggregation, but the system has a dedicated quota_data table for
aggregated statistics.

Removed:
- Grouping dropdown UI from filters
- Client-side grouping logic (getProcessedLogs)
- Grouping state management
- Group summary rendering in columns

The logs page is now focused on viewing detailed log records.
For aggregated statistics and grouping by user/model/time, users
should use the existing Data Dashboard (/api/data endpoints) which
properly leverages the quota_data table.

This aligns with the system architecture where:
- logs table = detailed per-request records
- quota_data table = hourly aggregated statistics

Co-authored-by: gmij <22893579+gmij@users.noreply.github.com>
@Claude Claude AI changed the title feat: display user display_name in logs and add grouping dropdown refactor: remove logs grouping, keep display_name feature Mar 13, 2026
Co-authored-by: gmij <22893579+gmij@users.noreply.github.com>
@Claude Claude AI changed the title refactor: remove logs grouping, keep display_name feature feat: add top users consumption ranking to dashboard Mar 13, 2026
@gmij
gmij marked this pull request as ready for review March 13, 2026 10:28
@gmij
gmij merged commit 0c8733d into main Mar 13, 2026
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