fix: sync local HTTP speed when online limit is applied#409
fix: sync local HTTP speed when online limit is applied#409zhaohuiw42 merged 1 commit intomasterfrom
Conversation
|
CLA Assistant Lite bot: |
deepin pr auto review这段 me analyze this git diff that modifies the download speed limit configuration logic in a Go application. Summary of ChangesThe changes modify how the system handles download speed limiting when switching between online and local speed limit modes. The key changes are:
Code Review1. Syntax and LogicPositive aspects:
Potential issues:
2. Code QualityPositive aspects:
Suggestions for improvement:
3. Code Performance
4. Code Security
Improvement Suggestions
// Instead of reflect.DeepEqual(downloadSpeed, oldDownloadSpeed)
if downloadSpeed == oldDownloadSpeed {
return nil
}This works because all fields in the struct are comparable (no slices, maps, or functions).
func (m *Manager) disableLocalSpeedLimitConfig(limitSpeed string) error {
// Validate limitSpeed if provided
if limitSpeed != "" {
if _, err := strconv.Atoi(limitSpeed); err != nil {
return fmt.Errorf("invalid speed limit value: %w", err)
}
}
// Rest of the function...
}
if downloadSpeed.DownloadSpeedLimitEnabled == oldDownloadSpeed.DownloadSpeedLimitEnabled &&
downloadSpeed.LimitSpeed == oldDownloadSpeed.LimitSpeed &&
downloadSpeed.IsOnlineSpeedLimit == oldDownloadSpeed.IsOnlineSpeedLimit {
return nil
}
func TestDisableLocalSpeedLimitConfigSyncsPlatformSpeedOnly(t *testing.T) {
tests := []struct {
name string
config string
newSpeed string
want downloadSpeedLimitConfig
}{
{
name: "update speed with valid value",
config: `{"DownloadSpeedLimitEnabled":true,"LimitSpeed":"888","IsOnlineSpeedLimit":false}`,
newSpeed: "666",
want: downloadSpeedLimitConfig{
DownloadSpeedLimitEnabled: false,
LimitSpeed: "666",
IsOnlineSpeedLimit: false,
},
},
{
name: "keep existing speed with empty value",
config: `{"DownloadSpeedLimitEnabled":true,"LimitSpeed":"888","IsOnlineSpeedLimit":false}`,
newSpeed: "",
want: downloadSpeedLimitConfig{
DownloadSpeedLimitEnabled: false,
LimitSpeed: "888",
IsOnlineSpeedLimit: false,
},
},
// Add more test cases as needed
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
manager := &Manager{
config: &config.Config{
LocalDownloadSpeedLimitConfig: tt.config,
},
}
err := manager.disableLocalSpeedLimitConfig(tt.newSpeed)
if err != nil {
t.Fatalf("disableLocalSpeedLimitConfig() error = %v", err)
}
var got downloadSpeedLimitConfig
if err := json.Unmarshal([]byte(manager.config.LocalDownloadSpeedLimitConfig), &got); err != nil {
t.Fatalf("LocalDownloadSpeedLimitConfig unmarshal error = %v", err)
}
if got != tt.want {
t.Fatalf("LocalDownloadSpeedLimitConfig = %+v, want %+v", got, tt.want)
}
})
}
}ConclusionThe changes implement the desired functionality of syncing the platform speed limit value when disabling local limits. The code is generally well-written and follows good practices. The main areas for improvement are:
These improvements would make the code more robust, maintainable, and efficient. |
|
[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. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Bug: https://pms.uniontech.com/bug-view-359485.html