-
Notifications
You must be signed in to change notification settings - Fork 2.5k
fix: Fix the problem of failed creation of child node snapshots #8898
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
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. |
if err != nil { | ||
return err | ||
} | ||
_ = snap.snapCoreDB.Exec("DELETE FROM operation_logs").Error | ||
} | ||
if !req.WithLoginLog { | ||
err = snap.snapCoreDB.Exec("DELETE FROM login_logs").Error |
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.
The code looks mostly clean and functional. However, the deletion of operation_logs
if withOperationLog
is false can be optimized slightly. Instead of using error checking for delete operations, one could simply check if the number of deleted rows is zero to ensure at least some records were cleared.
Here's an improved version:
@@ -268,11 +268,7 @@ func loadDbConn(snap *snapHelper, targetDir string, req dto.SnapshotCreate) erro
_ = taskDB.Where("id = ?", req.TaskID).Delete(&model.Task{}).Error
}
if !req.WithOperationLog {
- err = snap.snapCoreDB.Exec("DELETE FROM operation_logs").Error
- snap.Task.LogWithStatus(i18n.GetMsgByKey("SnapDeleteOperationLog"), err)
- if err != nil || res.RowsAffected == 0 {
- return err
- }
+ res := snap.snapCoreDB.Exec("DELETE FROM operation_logs")
+ if err := res.Error; err != nil || res.RowsAffected == 0 {
+ return err
}
This change reduces redundancy by combining the execution of the query with the error handling in one line, while still verifying that at least one row was deleted (as indicated by non-zero RowsAffected after executing the DELETE statement).
Additionally, I'm not sure where res
is used later in the function. If it's intended to use the result from the DELETE operation, this might need further modification based on its actual usage elsewhere in the code.
|
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.
/lgtm
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: wanghe-fit2cloud The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Refs #8897