-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix: 修改cronjob模块的功能 #10740
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
fix: 修改cronjob模块的功能 #10740
Conversation
|
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
感谢支持。 |
|
感谢反馈!这样确实能减少不少查询次数,但是直接上 sql 的话,会给后期维护带来一定的麻烦,目前 1panel 都是通过 gorm 框架实现,主要是方便维护。 是有在实际使用过程中,遇到了计划任务页面打开卡顿的情况吗? |
大概背景:我写了一个Python脚本,挂在定时任务上运行,每3分钟执行一次,由于间隔较短,所以留了1000分日志方便追溯;
|
是计划任务报告页面切换报告出现的卡顿,不是计划任务列表打开出现的卡顿吗? |
是在 计划任务 列表,点击 查看报告 后的页面;页面中左侧是执行记录,右侧是单个任务对应的日志; |

这个 PR 做了什么 / 为什么需要它?
优化定时任务列表的数据库查询性能,消除 N+1
查询问题。当前实现先执行一次主查询加载列表,然后对列表中的每条记录额外执行
一次查询来获取最后的执行状态。这导致 20 条记录会执行 21 次数据库查询。
改动总结
问题: 定时任务列表存在 N+1 查询问题
次查询
解决方案: 使用 LEFT JOIN 在一次查询中获取所有数据
修改的文件:
agent/app/repo/cronjob.go- 新增CronjobWithLastRecord结构体和PageWithRecord()方法(使用 LEFT JOIN)agent/app/service/cronjob.go- 更新SearchWithPage()方法使用优化后的查询方法
向后兼容: ✅ 完全兼容 - API 返回格式完全不变
Release Note
优化定时任务列表数据库查询性能。消除了导致单个列表页面加载 20+
次数据库查询的 N+1 问题。列表加载时间提升 80-90%,无需任何 API 改动。
请确认以下事项已完成: