Skip to content

优化: 任务日志查询速度并显示用户详情 - #2905

Merged
Calcium-Ion merged 2 commits into
QuantumNous:mainfrom
feitianbubu:pr/task-log-add-user-info
Feb 12, 2026
Merged

优化: 任务日志查询速度并显示用户详情#2905
Calcium-Ion merged 2 commits into
QuantumNous:mainfrom
feitianbubu:pr/task-log-add-user-info

Conversation

@feitianbubu

@feitianbubu feitianbubu commented Feb 10, 2026

Copy link
Copy Markdown
Member
  1. 去除每条任务日志查询一次用户详情
  2. 改为前端点击时查询用户详情
image

Summary by CodeRabbit

  • New Features

    • Interactive user avatars in task logs with tooltips.
    • Clickable user entries that open a user info modal.
  • Improvements

    • Reduced per-task lookups to speed up task data loading and rendering.

@coderabbitai

coderabbitai Bot commented Feb 10, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

Removed per-task Username population in backend TaskGetAllTasks and updated task-logs UI to display user info by user_id with an avatar+Tooltip and admin-only UserInfoModal; added hook state and function to fetch/show user details.

Changes

Cohort / File(s) Summary
Backend task model
model/task.go
Removed the loop that populated task.Username by calling GetUserCache for each task in TaskGetAllTasks (deleted per-task username assignment).
Frontend column defs
web/src/components/table/task-logs/TaskLogsColumnDefs.jsx
Changed USERNAME column to dataIndex: 'user_id'; render uses `record.username
Frontend table component
web/src/components/table/task-logs/TaskLogsTable.jsx
Destructures showUserInfoFunc from taskLogsData and passes it into getTaskLogsColumns; included in allColumns useMemo dependencies.
Frontend page component
web/src/components/table/task-logs/index.jsx
Imported and rendered UserInfoModal (../usage-logs/modals/UserInfoModal) inside TaskLogsPage, passing taskLogsData props.
Frontend hook
web/src/hooks/task-logs/useTaskLogsData.js
Added state showUserInfo, userInfoData, and showUserInfoFunc(userId) that (admin-only) GETs /api/user/${userId}, sets userInfoData, and opens modal; exposed these in the hook's returned API.
Misc (imports/manifest)
web/src/components/table/task-logs/..., package.json
Added Tooltip import from @douyinfe/semi-ui; small package/manifest edits referenced by the frontend changes.

Sequence Diagram

sequenceDiagram
    participant User
    participant UI as Task Logs UI
    participant Hook as useTaskLogsData
    participant API as Backend API
    participant Modal as UserInfoModal

    User->>UI: Click avatar / username cell
    UI->>Hook: showUserInfoFunc(userId)
    Hook->>Hook: verify admin?
    alt is admin
        Hook->>API: GET /api/user/{userId}
        API-->>Hook: user data
        Hook->>Hook: setUserInfoData(userData)
        Hook->>Hook: setShowUserInfoModal(true)
        Hook-->>UI: modal state updated
        UI->>Modal: render with userInfoData
        Modal-->>User: display user info
    else not admin
        Hook-->>UI: no-op / early return
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

  • feat: task log show username #2635: Modifies how task usernames are handled/populated; directly related to removal of per-task Username population and UI changes referencing user_id.

Poem

🐰 I nibbled code under moonlit logs so bright,

Avatars now hop into admin sight,
Click and a modal blooms — a friendly surprise,
User IDs whisper truth behind the eyes. ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main changes: optimizing task log query speed (by removing per-task user fetches) and displaying user details on frontend click.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

No actionable comments were generated in the recent review. 🎉

🧹 Recent nitpick comments
web/src/components/table/task-logs/TaskLogsColumnDefs.jsx (1)

21-21: Consolidate duplicate @douyinfe/semi-ui imports.

@douyinfe/semi-ui is imported on both Line 21 and Line 46. Merge them into a single import statement.

Proposed fix
-import { Progress, Tag, Tooltip, Typography } from '@douyinfe/semi-ui';
+import { Avatar, Progress, Space, Tag, Tooltip, Typography } from '@douyinfe/semi-ui';

And remove line 46:

-import { Avatar, Space } from '@douyinfe/semi-ui';

Also applies to: 46-46


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@web/src/components/table/task-logs/TaskLogsColumnDefs.jsx`:
- Around line 305-314: The Tooltip component is referenced in the
TaskLogsColumnDefs JSX (wrapping Avatar) but not imported, causing a runtime
ReferenceError; fix this by adding Tooltip to the existing Semi UI import that
currently brings in Avatar (i.e., include Tooltip alongside Avatar in the import
statement), then verify Tooltip is used as <Tooltip> around Avatar (which uses
displayText, userId, stringToColor, showUserInfoFunc) so the USERNAME column
renders without crashing.

In `@web/src/hooks/task-logs/useTaskLogsData.js`:
- Around line 280-293: The showUserInfoFunc currently calls
API.get(`/api/user/${userId}`) without catching network errors; wrap the body of
showUserInfoFunc in a try/catch, await API.get inside the try, and in catch call
showError with the caught error (handle AxiosError similarly to other hooks) so
network failures show a user-facing message; keep existing success handling that
calls setUserInfoData(data) and setShowUserInfoModal(true) and preserve the
non-admin early return.

Comment thread web/src/components/table/task-logs/TaskLogsColumnDefs.jsx
Comment on lines +280 to +293
// User info function
const showUserInfoFunc = async (userId) => {
if (!isAdminUser) {
return;
}
const res = await API.get(`/api/user/${userId}`);
const { success, message, data } = res.data;
if (success) {
setUserInfoData(data);
setShowUserInfoModal(true);
} else {
showError(message);
}
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Missing error handling for network failures.

API.get can throw on network errors (timeout, connection refused, etc.), which would result in an unhandled promise rejection with no user feedback. Wrap in try/catch, consistent with how showError already handles AxiosError.

Proposed fix
   const showUserInfoFunc = async (userId) => {
     if (!isAdminUser) {
       return;
     }
-    const res = await API.get(`/api/user/${userId}`);
-    const { success, message, data } = res.data;
-    if (success) {
-      setUserInfoData(data);
-      setShowUserInfoModal(true);
-    } else {
-      showError(message);
+    try {
+      const res = await API.get(`/api/user/${userId}`);
+      const { success, message, data } = res.data;
+      if (success) {
+        setUserInfoData(data);
+        setShowUserInfoModal(true);
+      } else {
+        showError(message);
+      }
+    } catch (error) {
+      showError(error);
     }
   };
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// User info function
const showUserInfoFunc = async (userId) => {
if (!isAdminUser) {
return;
}
const res = await API.get(`/api/user/${userId}`);
const { success, message, data } = res.data;
if (success) {
setUserInfoData(data);
setShowUserInfoModal(true);
} else {
showError(message);
}
};
// User info function
const showUserInfoFunc = async (userId) => {
if (!isAdminUser) {
return;
}
try {
const res = await API.get(`/api/user/${userId}`);
const { success, message, data } = res.data;
if (success) {
setUserInfoData(data);
setShowUserInfoModal(true);
} else {
showError(message);
}
} catch (error) {
showError(error);
}
};
🤖 Prompt for AI Agents
In `@web/src/hooks/task-logs/useTaskLogsData.js` around lines 280 - 293, The
showUserInfoFunc currently calls API.get(`/api/user/${userId}`) without catching
network errors; wrap the body of showUserInfoFunc in a try/catch, await API.get
inside the try, and in catch call showError with the caught error (handle
AxiosError similarly to other hooks) so network failures show a user-facing
message; keep existing success handling that calls setUserInfoData(data) and
setShowUserInfoModal(true) and preserve the non-admin early return.

@Calcium-Ion
Calcium-Ion merged commit 30da5bb into QuantumNous:main Feb 12, 2026
1 check passed
hardingCheng pushed a commit to hardingCheng/new-api that referenced this pull request Feb 14, 2026
* main: (21 commits)
  fix: normalize search pagination params to avoid [object Object]
  fix: ignore header passthrough during channel tests
  fix(token-search): use TrimPrefix for sk- token normalization
  fix: rename bulk test action to skip manually disabled channels
  fix: support numeric status code mapping in ResetStatusCode
  优化: 任务日志查询速度并显示用户详情 (QuantumNous#2905)
  Merge pull request QuantumNous#2916 from worryzyy/feature/add-quota-amount-input
  feat: Improve backend multilingual support
  feat: add OpenRouter pricing support to upstream ratio sync
  feat: refactor request body handling to use BodyStorage for improved efficiency
  feat(xai): 为xAI渠道添加/v1/responses支持 (QuantumNous#2897)
  chore: remove deprecated Docker badge from README
  feat: refactor extra_body handling for improved configuration parsing
  Update README
  feat: logs cache field (QuantumNous#2920)
  feat(localization): added zh_TW (QuantumNous#2913)
  fix: update README files to improve link formatting and readability
  feat: add Aion UI link to README files
  chore(deps): bump axios from 1.12.0 to 1.13.5 in /web
  simplify language selector display to use text-only labels
  ...

# Conflicts:
#	web/src/components/layout/headerbar/LanguageSelector.jsx
ennnnny pushed a commit to ennnnny/new-api that referenced this pull request Mar 17, 2026
* perf: task log show userinfo

* feat: add Tooltip component to TaskLogsColumnDefs
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