-
-
Notifications
You must be signed in to change notification settings - Fork 592
feat: Add key sorting threshold #377
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
* feat: Add keys_sort_max_count setting + group override * feat: Track api_keys.last_used_at from request logs * feat: Conditional keys sorting + UI toggle via last_used_enabled
…+RowsAffected in key handler
WalkthroughThe PR implements a configurable threshold-based mechanism for sorting API keys by last-used time. A probe query checks if the threshold is exceeded; if not, sorting by last-used is enabled. The system tracks key usage timestamps and updates them during request logging, with conditional UI display based on an enabled flag passed in API response metadata. Changes
Sequence Diagram(s)sequenceDiagram
participant Frontend as Frontend (KeyTable)
participant Handler as Handler (ListKeysInGroup)
participant DB as Database
participant Service as KeyService
Frontend->>Handler: GET /keys (group_id, page, page_size)
Handler->>DB: SELECT group WHERE id = ?
DB-->>Handler: Group object + Config
Handler->>DB: Probe: SELECT * LIMIT ? OFFSET threshold
DB-->>Handler: Row result (RowsAffected)
Handler->>Handler: lastUsedEnabled = (RowsAffected == 0)
Handler->>Service: ListKeysInGroupQuery(groupID, filters, lastUsedEnabled)
Service->>Service: Build ORDER BY clause based on lastUsedEnabled
alt lastUsedEnabled = true
Service->>DB: ORDER BY last_used_at DESC, updated_at DESC
else lastUsedEnabled = false
Service->>DB: ORDER BY id DESC
end
DB-->>Service: Keys result set
Service-->>Handler: Query result
Handler->>Handler: Decrypt keys
Handler->>Handler: Inject lastUsedEnabled into Meta
Handler-->>Frontend: { items, pagination, meta: { last_used_enabled } }
Frontend->>Frontend: Read meta.last_used_enabled
Frontend->>Frontend: Conditionally render last-used badge
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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 |
|
感谢你的贡献,抱歉不能合并你的代码。我会用另外一种方式来恢复 |
恢复了key的
last_used_at的使用,默认10000key以内会触发,超过设定的阈值不会触发,对性能没有影响;增加了相关的设置UI。关联 Issue / Related Issue
无
变更内容 / Change Content
自查清单 / Checklist
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.