Skip to content

fix: keep usage log filters exact unless wildcard is explicit - #5097

Merged
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
yyhhyyyyyy:fix/usage-logs-explicit-fuzzy-search
May 26, 2026
Merged

fix: keep usage log filters exact unless wildcard is explicit#5097
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
yyhhyyyyyy:fix/usage-logs-explicit-fuzzy-search

Conversation

@yyhhyyyyyy

@yyhhyyyyyy yyhhyyyyyy commented May 25, 2026

Copy link
Copy Markdown
Contributor

⚠️ 提交说明 / PR Notice

Important

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

📝 变更描述 / Description

(简述:做了什么?为什么这样改能生效?请基于你对代码逻辑的理解来写,避免粘贴未经整理的内容)
使用日志默认改为精确匹配,避免自动 %keyword% 模糊查询打穿索引。
仅当用户显式输入 % 时才启用 LIKE 模糊匹配;同时恢复前端服务端过滤,避免分页结果被本地二次过滤。

🚀 变更类型 / Type of change

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

🔗 关联任务 / Related Issue

  • Closes # (如有)

✅ 提交前检查项 / Checklist

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

📸 运行证明 / Proof of Work

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

Summary by CodeRabbit

  • Bug Fixes

    • Improved log query filtering to support both exact matching and pattern-based searches intelligently based on input format.
  • Improvements

    • Migrated table filtering to server-side processing for better performance on large datasets.
    • Made the usage logs type filter optional, allowing more flexible route navigation.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 25, 2026

Copy link
Copy Markdown
Contributor

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: c66a5f23-1cb5-4c09-9b08-e842385fdf97

📥 Commits

Reviewing files that changed from the base of the PR and between 583da45 and a7dc6e9.

📒 Files selected for processing (3)
  • model/log.go
  • web/default/src/features/usage-logs/components/usage-logs-table.tsx
  • web/default/src/routes/_authenticated/usage-logs/$section.tsx

Walkthrough

The PR centralizes log query filtering logic by introducing a helper function that conditionally applies exact-match or wildcard-safe filtering based on input content. The backend updates three log retrieval functions to use this helper, while the frontend enables server-side filtering in the table configuration and makes the search type parameter optional.

Changes

Server-side log filtering implementation

Layer / File(s) Summary
Text filter helper and support
model/log.go
Added strings import and introduced applyExplicitLogTextFilter helper to centralize conditional filtering logic: exact-match = when input lacks %, and LIKE ... ESCAPE '!' when % is present. Struct field formatting aligned in the diff.
Apply helper to log query functions
model/log.go
Refactored GetAllLogs, GetUserLogs, and SumUsedQuota to replace inline conditional filtering with applyExplicitLogTextFilter calls for model_name, username, and token_name, with consistent error propagation.
Frontend filtering configuration
web/default/src/features/usage-logs/components/usage-logs-table.tsx, web/default/src/routes/_authenticated/usage-logs/$section.tsx
Enabled server-side filtering by setting manualFiltering: true in useReactTable, and made type search parameter optional in the route schema to support dynamic filter handling.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • QuantumNous/new-api#4883: Both PRs refactor model/log.go usage-log query filtering for logs.model_name, logs.username, and logs.token_name to use shared helper-based LIKE/pattern logic (replacing prior conditional =/LIKE behavior), and also align UsageLogsTable to manualFiltering: true.

Poem

🐰 The filters now dance in harmony fine,
One helper to rule them, by value or sign—
When percent marks appear, we escape with great care,
Server-side filtering floating through air!

🚥 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 clearly and concisely summarizes the main change: converting usage log filters from fuzzy/wildcard matching to exact matching by default, with wildcards only applied when explicitly provided by the user.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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.

@Calcium-Ion
Calcium-Ion merged commit 1d32037 into QuantumNous:main May 26, 2026
2 checks passed
52assert added a commit to 52assert/new-api that referenced this pull request May 28, 2026
…codes

* origin/main: (34 commits)
  fix: optimize batch update process
  fix: keep token log filters exact
  fix: keep usage log filters exact unless wildcard is explicit (QuantumNous#5097)
  fix(web): improve channel and usage log UI
  feat(theme): add simple-large preset, xl scale and clean up channel badge dots
  🐛 fix(system-settings): resolve save detection and number input NaN issues
  🎨 fix(logs): tune usage table typography
  fix: use actual user id for channel tests (QuantumNous#5109)
  fix: consolidate Waffo payment settings save flow (QuantumNous#5110)
  🎨 fix(charts): improve dark mode chart readability
  🎨 fix(logs): remove hardcoded font-mono to support global theme font inheritance
  🎨 fix(logs): restore timing background badges and optimize model/token spacing
  feat(subscription): support balance purchases
  🎨 fix(theme): default theme font preset falls back to Sans instead of Serif
  🎨 refactor(badge): restore status-badge sizes and classic color scheme
  fix: prevent duplicate channel action toasts (QuantumNous#5015)
  🎨 feat(web/default): add Anthropic theme preset and configurable serif typography
  ♻️ refactor(channels): rebuild channel editor UX with modular sections and Base UI multi-select
  ♻️ refactor(channels): rebuild channel create/edit drawer with modular sections and improved form UX
  fix: handle paginated API key search response (QuantumNous#5014)
  ...

# Conflicts:
#	controller/misc.go
#	web/default/src/features/auth/sign-in/components/user-auth-form.tsx
#	web/default/src/features/auth/sign-in/index.tsx
#	web/default/src/features/auth/sign-up/components/sign-up-form.tsx
#	web/default/src/hooks/use-sidebar-data.ts
#	web/default/src/routes/__root.tsx
SamuelSxy pushed a commit to SamuelSxy/new-api-rh that referenced this pull request Jun 7, 2026
fx247562340 pushed a commit to fx247562340/vancine-platform that referenced this pull request Jun 11, 2026
@coderabbitai coderabbitai Bot mentioned this pull request Jun 30, 2026
11 tasks
330079598 pushed a commit to 330079598/new-api that referenced this pull request Aug 19, 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