Skip to content

fix: set default rate limit to 10240#408

Merged
zhaohuiw42 merged 1 commit intolinuxdeepin:masterfrom
zhaohuiw42:master
May 7, 2026
Merged

fix: set default rate limit to 10240#408
zhaohuiw42 merged 1 commit intolinuxdeepin:masterfrom
zhaohuiw42:master

Conversation

@zhaohuiw42
Copy link
Copy Markdown
Contributor

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 6, 2026

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.

You can retrigger this bot by commenting recheck in this Pull Request

@zhaohuiw42 zhaohuiw42 changed the title fix: set default rate limit to 1024 fix: set default rate limit to 10240 May 6, 2026
@deepin-ci-robot
Copy link
Copy Markdown

deepin pr auto review

这段代码修改主要是关于系统更新服务的默认下载/上传速率限制的调整。以下是对代码的详细审查和改进建议:

1. 代码逻辑与功能分析

变更内容

  • DefaultRateLimit10 * 1024 (10KB/s) 提升到 10240 * 1024 (10MB/s)
  • 同步更新了所有相关的默认配置值(JSON配置文件和常量定义)
  • 在单元测试中增加了对 LimitRateCurrentRate 的断言检查

逻辑一致性

  • 代码逻辑是一致的,所有涉及默认速率的地方都进行了同步更新
  • 速率单位统一为 bytes per second (B/s)
  • 测试代码的补充是合理的,确保了默认值变更后的正确性

2. 代码质量改进建议

(1) 常量命名与可读性

// 当前写法
const DefaultRateLimit = 10240 * 1024 // 10240KB/s unit: bytes per second

// 建议改进:使用更明确的计算方式,提高可读性
const (
    KB = 1024
    MB = 1024 * KB
    DefaultRateLimit = 10 * MB // 10MB/s
    MinRateLimit = 10 * KB     // 10KB/s
    MaxRateLimit = 999999 * KB // ~976MB/s
)

(2) JSON配置中的硬编码问题

org.deepin.dde.lastore.json 中存在大量重复的JSON字符串,建议:

// 建议在代码中统一生成这些配置,而不是在JSON文件中硬编码
func getDefaultRateLimitConfig(rate int64) string {
    return fmt.Sprintf(`{"LimitType":0,"StartTime":"0001-01-01T00:00:00Z","EndTime":"0001-01-01T00:00:00Z","LimitRate":%d,"CurrentRate":%d}`, 
        rate, rate)
}

3. 性能考虑

  • 当前修改不会对性能产生负面影响
  • 增加的测试断言仅在测试时执行,不影响生产环境性能
  • 建议考虑在高并发场景下验证新的默认速率限制是否合理

4. 安全性建议

  1. 速率限制范围验证
// 建议添加验证函数
func validateRateLimit(rate int64) bool {
    return rate >= MinRateLimit && rate <= MaxRateLimit
}

// 在设置速率时调用
if !validateRateLimit(newRate) {
    return errors.New("rate limit out of range")
}
  1. 配置文件安全
  • 确保 org.deepin.dde.lastore.json 文件的权限设置正确(建议644)
  • 避免在配置文件中包含敏感信息

5. 其他建议

  1. 文档更新

    • 确保更新相关文档,说明新的默认速率限制
    • 记录变更原因(例如:为了适应现代网络环境)
  2. 向后兼容性

    • 考虑是否需要处理旧配置文件的迁移
    • 如果用户已自定义配置,确保不会意外覆盖
  3. 测试覆盖

// 建议添加边界测试
func TestRateLimitBounds(t *testing.T) {
    tests := []struct {
        name  string
        rate  int64
        valid bool
    }{
        {"below min", MinRateLimit - 1, false},
        {"min", MinRateLimit, true},
        {"default", DefaultRateLimit, true},
        {"max", MaxRateLimit, true},
        {"above max", MaxRateLimit + 1, false},
    }
    // ... 测试实现
}

总结

这次修改主要是调整了默认的速率限制值,代码逻辑正确,但建议:

  1. 提高常量定义的可读性
  2. 减少JSON配置中的硬编码
  3. 添加速率范围验证
  4. 完善测试用例
  5. 确保文档同步更新

这些改进将使代码更健壮、更易于维护,同时提高系统的安全性和可靠性。

@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

@zhaohuiw42 zhaohuiw42 merged commit 7cbe44e into linuxdeepin:master May 7, 2026
14 of 17 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