Skip to content

fix: Adapt the maximum speed limit logic for incremental updates.#246

Merged
qiuzhiqian merged 1 commit into
linuxdeepin:masterfrom
qiuzhiqian:master
Oct 28, 2025
Merged

fix: Adapt the maximum speed limit logic for incremental updates.#246
qiuzhiqian merged 1 commit into
linuxdeepin:masterfrom
qiuzhiqian:master

Conversation

@qiuzhiqian
Copy link
Copy Markdown
Contributor

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Oct 28, 2025

CLA Assistant Lite bot:
提交邮箱中包含我们的合作伙伴,但您似乎并非合作伙伴的成员或对接人,请联系相关对接人将您添加至组织之中,或由其重新发起 Pull Request。
The commit email domain belongs to one of our partners, but it seems you are not yet a member of the current organization, please contact the contact person to add you to the organization or let them submit the Pull Request.

xml seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You can retrigger this bot by commenting recheck in this Pull Request

@deepin-ci-robot
Copy link
Copy Markdown

deepin pr auto review

我来对这个diff进行仔细的审查:

  1. 代码逻辑改进:
  • 在apt.go中,修改了IncrementalDownloadJobType和IncrementalUpdateJobType的命令行构建方式,现在可以动态添加额外的命令行参数。这是一个好的改进,提高了代码的灵活性。
  1. 代码质量改进:
  • 在proxy.go中引入了常量aptLimitKey,避免了魔法字符串的使用,提高了代码可维护性。
  • 使用ok模式检查map中的值,这是Go语言的惯用写法,代码质量较好。
  1. 代码性能改进:
  • 使用append动态构建参数列表,避免了不必要的内存分配,性能考虑合理。
  1. 代码安全改进:
  • 对用户输入的参数进行了适当的处理,通过固定基础参数再追加额外参数的方式,避免了命令注入的风险。
  1. 潜在问题和改进建议:

a) 错误处理:

speedLimit, ok := args[aptLimitKey]
if ok {
    cmdArgs = append(cmdArgs, "--max-recv-speed", speedLimit)
}

建议对speedLimit进行有效性验证,确保它是一个合法的数值:

if speedLimit, ok := args[aptLimitKey]; ok {
    if _, err := strconv.ParseFloat(speedLimit, 64); err == nil {
        cmdArgs = append(cmdArgs, "--max-recv-speed", speedLimit)
    }
}

b) 参数传递:
在DownloadSource和DistUpgrade方法中,packages参数似乎被忽略了。如果这是预期的行为,建议添加注释说明原因。如果不是,需要修正这个问题。

c) 代码复用:
两个方法中有相似的speed limit处理逻辑,建议提取为公共函数:

func buildSpeedLimitArgs(args map[string]string) []string {
    if speedLimit, ok := args[aptLimitKey]; ok {
        if _, err := strconv.ParseFloat(speedLimit, 64); err == nil {
            return []string{"--max-recv-speed", speedLimit}
        }
    }
    return nil
}

d) 日志记录:
建议在添加speed limit参数时添加日志记录,便于调试:

if speedLimit, ok := args[aptLimitKey]; ok {
    logger.Debugf("Setting download speed limit to: %s", speedLimit)
    cmdArgs = append(cmdArgs, "--max-recv-speed", speedLimit)
}

总的来说,这个diff的改进是积极的,主要提高了代码的灵活性和可维护性。建议考虑上述改进建议,特别是关于错误处理和参数验证的部分。

@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: qiuzhiqian, zhaohuiw42

The full list of commands accepted by this bot can be found here.

Details 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

@qiuzhiqian qiuzhiqian merged commit a7f4b56 into linuxdeepin:master Oct 28, 2025
12 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants