Skip to content

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

Merged
merged 1 commit into from
Jun 3, 2025

Conversation

ssongliu
Copy link
Member

@ssongliu ssongliu commented Jun 3, 2025

Refs #8897

Copy link

f2c-ci-robot bot commented Jun 3, 2025

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
Copy link
Member

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.

Copy link

sonarqubecloud bot commented Jun 3, 2025

Copy link
Member

@wanghe-fit2cloud wanghe-fit2cloud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@wanghe-fit2cloud
Copy link
Member

/approve

Copy link

f2c-ci-robot bot commented Jun 3, 2025

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@f2c-ci-robot f2c-ci-robot bot added the approved label Jun 3, 2025
@f2c-ci-robot f2c-ci-robot bot merged commit 7bc2bbc into dev-v2 Jun 3, 2025
7 checks passed
@f2c-ci-robot f2c-ci-robot bot deleted the pr@dev-v2@fix_snapshot branch June 3, 2025 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants