-
Notifications
You must be signed in to change notification settings - Fork 2.9k
fix: 编辑计划任务和病毒扫描告警问题处理 #7047
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
Merged
Merged
fix: 编辑计划任务和病毒扫描告警问题处理 #7047
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -316,15 +316,17 @@ func (u *CronjobService) Update(id uint, req dto.CronjobUpdate) error { | |
| if err != nil { | ||
| return err | ||
| } | ||
| updateAlert := dto.CreateOrUpdateAlert{ | ||
| AlertTitle: req.AlertTitle, | ||
| AlertType: cronModel.Type, | ||
| AlertCount: req.AlertCount, | ||
| EntryID: cronModel.ID, | ||
| } | ||
| err = xpack.UpdateAlert(updateAlert) | ||
| if err != nil { | ||
| return err | ||
| if req.AlertCount != 0 { | ||
| updateAlert := dto.CreateOrUpdateAlert{ | ||
| AlertTitle: req.AlertTitle, | ||
| AlertType: cronModel.Type, | ||
| AlertCount: req.AlertCount, | ||
| EntryID: cronModel.ID, | ||
| } | ||
| err = xpack.UpdateAlert(updateAlert) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个代码没有明显的问题或需要改进的地方。它看起来已经是最新版本,并且逻辑已经正确无误。然而,为了进一步完善性能和可读性,可以考虑:
func (u *CronjobService) UpdateByID(id uint, req dto.CronjobUpdateRequest) error {
if err := validate(req); err != nil {
return errors.Wrap(err, "request validation failed")
}
updateAlert := dto.CreateOrUpdateAlert{
AlertTitle: req.GetAlert.Title(),
// 可以将其他字段从req复制到updateAlert的字段中...
AlertType: cronModel.Type,
AlertCount: int(req.GetAlert.Count()),
EntryID: id.ToString()
},
result, _, err
if !errors.IsNotFoundError(err){
}
```
3. 建议在每次操作之前验证输入数据。
4. 如果有更多cronjobs存在,则推荐使用分页查找/删除的方法而不是更新整个collection中的所有元素,在性能优化方面有很大的提升空间。
这是最基础的更改思路,更具体的改进建议取决于需求及实际应用场景的具体情况。 |
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个函数主要负责更新一个名叫"clams"的告警(alert)。在当前版本中,代码是有效的,并且没有发现需要改进的地方。
然而,在2021年之前可能存在一些问题:
err.Error()来打印错误信息,避免将错误写入日志。var updateAlert = dto.CreateOrUpdateAlert{}来简化代码。总体来说,如果只考虑性能和效率的影响,并没有明显的不合规或问题。
关于优化建议:保持简洁、清晰的编程风格,并经常进行单元测试。