fix: correct usage logs filtering#4883
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughThree 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. ChangesLog Search Filtering Refactoring
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Calcium-Ion
left a comment
There was a problem hiding this comment.
LGTM. 审了 diff:
后端 (model/log.go):
- 统一抽取了
logContainsPattern/applyLogContainsFilter函数,将所有 username/token_name/model_name 的过滤从精确匹配=/ 或不一致的 LIKE 改为统一的%escaped_input%模糊匹配。 - LIKE ESCAPE '!' 处理正确:先转义
!/%/_特殊字符,再两端加%。 LIKE ... ESCAPE '!'语法三库(SQLite/MySQL/PostgreSQL)都支持,无兼容问题。GetAllLogs、GetUserLogs、SumUsedQuota三个函数都统一了。
前端 (usage-logs-table.tsx):
- 加了
manualFiltering: true— 正确,因为过滤是服务端做的,不需要 react-table 的客户端过滤。
逻辑清晰,消除了重复代码。
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>
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>
Important
📝 变更描述 / Description
(简述:做了什么?为什么这样改能生效?请基于你对代码逻辑的理解来写,避免粘贴未经整理的内容)
完善使用日志查询。
🚀 变更类型 / Type of change
🔗 关联任务 / Related Issue
✅ 提交前检查项 / Checklist
Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。📸 运行证明 / Proof of Work
(请在此粘贴截图、关键日志或测试报告,以证明变更生效)

Summary by CodeRabbit
Release Notes