Skip to content

fix: correct usage logs filtering#4883

Merged
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
yyhhyyyyyy:fix/usage-logs-filtering
May 16, 2026
Merged

fix: correct usage logs filtering#4883
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
yyhhyyyyyy:fix/usage-logs-filtering

Conversation

@yyhhyyyyyy
Copy link
Copy Markdown
Contributor

@yyhhyyyyyy yyhhyyyyyy commented May 15, 2026

⚠️ 提交说明 / PR Notice

Important

  • 请提供人工撰写的简洁摘要,避免直接粘贴未经整理的 AI 输出。

📝 变更描述 / Description

(简述:做了什么?为什么这样改能生效?请基于你对代码逻辑的理解来写,避免粘贴未经整理的内容)
完善使用日志查询。

🚀 变更类型 / Type of change

  • 🐛 Bug 修复 (Bug fix) - 请关联对应 Issue,避免将设计取舍、理解偏差或预期不一致直接归类为 bug
  • ✨ 新功能 (New feature) - 重大特性建议先通过 Issue 沟通
  • ⚡ 性能优化 / 重构 (Refactor)
  • 📝 文档更新 (Documentation)

🔗 关联任务 / Related Issue

✅ 提交前检查项 / Checklist

  • 人工确认: 我已亲自整理并撰写此描述,没有直接粘贴未经处理的 AI 输出。
  • 非重复提交: 我已搜索现有的 IssuesPRs,确认不是重复提交。
  • Bug fix 说明: 若此 PR 标记为 Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。
  • 变更理解: 我已理解这些更改的工作原理及可能影响。
  • 范围聚焦: 本 PR 未包含任何与当前任务无关的代码改动。
  • 本地验证: 已在本地运行并通过测试或手动验证,维护者可以据此复核结果。
  • 安全合规: 代码中无敏感凭据,且符合项目代码规范。

📸 运行证明 / Proof of Work

(请在此粘贴截图、关键日志或测试报告,以证明变更生效)
image

Summary by CodeRabbit

Release Notes

  • Improvements
    • Enhanced log filtering to use consistent pattern matching across all search fields, improving search reliability.
    • Updated usage logs table filtering to work more efficiently with the system.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 15, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5a453454-f830-4e9c-b88e-edd851e1f6b2

📥 Commits

Reviewing files that changed from the base of the PR and between 18282e6 and 3de5806.

📒 Files selected for processing (2)
  • model/log.go
  • web/default/src/features/usage-logs/components/usage-logs-table.tsx

Walkthrough

Three log query functions and the usage logs table are refactored to unify filtering behavior. A new shared pattern builder implements contains-style partial matching with wildcard escaping, replacing prior conditional exact-match and full-name-only LIKE logic. The frontend table enables manual filtering mode.

Changes

Log Search Filtering Refactoring

Layer / File(s) Summary
Log search pattern builder and quota filtering
model/log.go
New helpers logContainsPattern and applyLogContainsFilter trim input, escape LIKE special characters with ESCAPE '!', and build %...% patterns. SumUsedQuota applies these helpers to username, token_name, and model_name instead of prior direct equality checks.
GetAllLogs filter application
model/log.go
GetAllLogs uses applyLogContainsFilter for model_name, username, and token_name, replacing conditional exact/LIKE behavior with uniform contains-style LIKE when non-empty.
GetUserLogs filter application
model/log.go
GetUserLogs applies applyLogContainsFilter to both model_name and token_name, replacing prior sanitizeLikePattern LIKE for model_name and equality check for token_name.
Frontend manual filtering configuration
web/default/src/features/usage-logs/components/usage-logs-table.tsx
useReactTable configuration adds manualFiltering: true alongside existing manualPagination: true, enabling external filtering control.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A rabbit hops through search fields wide,
With patterns trimmed and wildcards typed,
No more just exact matches hide—
Partial names now safely find their stride!
ESCAPE '!' guards the query's guide.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: correct usage logs filtering' directly corresponds to the main purpose of this PR—fixing and improving search/filter behavior in usage logs.
Linked Issues check ✅ Passed The code changes address the bug fix for channel ID filtering and implement contains-style filtering for token name and username, matching the two objectives in issue #4879.
Out of Scope Changes check ✅ Passed All changes are directly related to the usage logs filtering fix. The refactored log.go query logic and manualFiltering configuration change are both necessary and in-scope for the stated objectives.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

Copy link
Copy Markdown
Collaborator

@Calcium-Ion Calcium-Ion left a comment

Choose a reason for hiding this comment

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

LGTM. 审了 diff:

后端 (model/log.go)

  1. 统一抽取了 logContainsPattern / applyLogContainsFilter 函数,将所有 username/token_name/model_name 的过滤从精确匹配 = / 或不一致的 LIKE 改为统一的 %escaped_input% 模糊匹配。
  2. LIKE ESCAPE '!' 处理正确:先转义 ! / % / _ 特殊字符,再两端加 %
  3. LIKE ... ESCAPE '!' 语法三库(SQLite/MySQL/PostgreSQL)都支持,无兼容问题。
  4. GetAllLogsGetUserLogsSumUsedQuota 三个函数都统一了。

前端 (usage-logs-table.tsx)

  • 加了 manualFiltering: true — 正确,因为过滤是服务端做的,不需要 react-table 的客户端过滤。

逻辑清晰,消除了重复代码。

@Calcium-Ion Calcium-Ion merged commit 554defe into QuantumNous:main May 16, 2026
2 checks passed
jingx8885 added a commit to jingx8885/new-api that referenced this pull request May 17, 2026
Resolve model/log.go conflict:
- Adopt upstream logContainsPattern/applyLogContainsFilter (QuantumNous#4883), drop
  removed sanitizeLikePattern.
- Keep fork BatchConsume* structs, GetBatchConsumeLogs, enrichLogChannelNames;
  migrate GetBatchConsumeLogs model_name filter to applyLogContainsFilter.
- Preserve exact match (= ?) for username/token_name in GetAllLogs/
  GetUserLogs/SumUsedQuota so LovBrowser per-user/token billing does not
  cross-match; model_name keeps upstream substring behavior.

LovBrowser contract impact verified: only QuantumNous#4883 was relevant; exact-match
preservation means no LovBrowser code change required. Other 7 upstream
commits (channel group filter, header nav access, frontend fixes) do not
touch LovBrowser-consumed contracts.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
chenglu added a commit to chenglu/new-api that referenced this pull request May 17, 2026
Merged 28 commits from QuantumNous/new-api upstream/main, including:

Backend:
- feat: support request_header key source (QuantumNous#4903)
- fix: apply group filter to channel list queries (QuantumNous#4885, QuantumNous#4847)
- fix: enforce header nav access control for public modules (QuantumNous#4889)
- fix: correct usage logs filtering (QuantumNous#4883)
- fix: allow clearing channel remark (QuantumNous#4886)
- feat: track upstream request ID and prevent response header override
- feat: require compliance confirmation for paid features

Frontend:
- fix: 修复新 UI 语言与文案显示问题 (QuantumNous#4876)
- fix(web): handle unlimited API key quota validation (QuantumNous#4881)
- fix(web/default): batch fix new UI issues (QuantumNous#4880, QuantumNous#4893, QuantumNous#4817, QuantumNous#4877, QuantumNous#4898)
- fix: prevent combobox from over-filtering options on focus (QuantumNous#4829)
- fix(default): support DropdownMenuItem onSelect (QuantumNous#4787)
- chore(deps): bump axios to 1.15.2

Conflict resolution:
- Locale JSONs: union merge (design overrides preserved, upstream new keys added)
- router/api-router.go: kept design /public/session route, accepted upstream HeaderNavModuleAuth
- common-logs-filter-bar.tsx: kept design refactor, added upstream upstreamRequestId field
- summary-cards.tsx: kept design layout, adapted to new useSummaryCardsConfig interface
- _reports/*.untranslated.json: design state kept (fr/vi removed, ja/ru ours)
- Other UI conflicts resolved per .gitattributes ours strategy

Co-authored-by: Cursor <cursoragent@cursor.com>
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.

v1.0.0-rc.6 使用日志中--渠道ID--搜索无效,且使用“令牌名称”和“用户名”搜索只能搜全名

2 participants