Skip to content

feat: add update source success process event#297

Merged
qiuzhiqian merged 1 commit into
intranet_updatefrom
fix_intranet
Jan 23, 2026
Merged

feat: add update source success process event#297
qiuzhiqian merged 1 commit into
intranet_updatefrom
fix_intranet

Conversation

@qiuzhiqian

Copy link
Copy Markdown
Contributor

@github-actions

github-actions Bot commented Jan 23, 2026

Copy link
Copy Markdown

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

我已经仔细审查了你提供的 git diff 代码,以下是关于语法逻辑、代码质量、代码性能和代码安全的详细审查意见及改进建议:

1. 语法逻辑

文件:src/internal/updateplatform/message_report.go

  • 改动点:在 PostProcessEventMessage 函数开头添加了 system.IsPrivateLastore 的判断。
  • 审查意见:逻辑上看起来是合理的,用于区分私有版和社区版的功能差异。如果 IsPrivateLastore 为 false,则不处理后续的消息。

文件:src/lastore-daemon/manager_update.go

  • 改动点:在 updateSource 方法的 goroutine 中,除了发送 PostStatusMessage 外,新增了对 PostProcessEventMessage 的调用。
  • 审查意见
    • 变量作用域msgContent 被定义在 goroutine 内部,这是正确的做法,避免了闭包捕获外部变量的问题。
    • 逻辑连贯性:在更新源成功后发送处理事件,逻辑上是通顺的。

2. 代码质量

文件:src/internal/updateplatform/message_report.go

  • 建议:建议在 PostProcessEventMessage 函数中添加注释,说明为什么私有版需要特殊处理,或者这个判断的具体业务含义。例如:// 仅在私有版环境下处理事件消息

文件:src/lastore-daemon/manager_update.go

  • 硬编码问题
    • TaskID: 1:这里的 TaskID 被硬编码为 1。在 message_report.goUpdateAllPlatformDataSync 函数中可以看到 body.TaskID = m.taskID,说明该结构体通常使用 m.taskID。这里硬编码 1 可能会导致日志追踪或任务关联时出现 ID 不一致的问题。
    • 改进建议:检查 mManager 结构体)或 m.updatePlatform 是否有当前任务 ID 的字段,如果有,应该使用该字段,而不是硬编码 1
  • 魔法值
    • msgContent := "update source success":虽然可读性尚可,但建议提取为常量,便于统一维护和国际化(如果需要)。

3. 代码性能

  • 审查意见
    • message_report.go 中增加的 if 判断非常轻量,对性能几乎无影响。
    • manager_update.go 中,新增的 PostProcessEventMessage 调用发生在 goroutine 中,不会阻塞主流程,性能影响可控。
    • PostProcessEventMessage 内部如果涉及到网络 I/O 或磁盘 I/O,请确保其实现是异步或高效的,以免阻塞 updateSource 中的 goroutine 过久,虽然这不会阻塞主业务,但可能影响自动退出(inhibitAutoQuitCount)的计时。

4. 代码安全

  • 审查意见
    • 输入验证PostProcessEventMessage 接收 ProcessEvent 结构体。虽然在这个 diff 中调用方是受控的,但建议检查 PostProcessEventMessage 内部是否对 EventContent(即 msgContent)进行了长度限制或特殊字符过滤,以防止潜在的日志注入或缓冲区溢出(取决于底层存储/传输实现)。
    • 并发安全m.updatePlatform 的方法 PostProcessEventMessage 被调用。请确保 UpdatePlatformManager 内部的状态在并发调用下是安全的,特别是如果它涉及共享资源的写入。

综合改进建议代码

针对 src/lastore-daemon/manager_update.go 的改进建议:

// 建议在文件顶部或适当位置定义常量
const (
    msgUpdateSourceSuccess = "update source success"
)

// ... 在 updateSource 方法中 ...

go func() {
    m.inhibitAutoQuitCountAdd()
    defer m.inhibitAutoQuitCountSub()
    
    // 使用常量
    msgContent := msgUpdateSourceSuccess
    
    m.updatePlatform.PostStatusMessage(updateplatform.StatusMessage{
        Type:   "info",
        Detail: msgContent,
    }, false)

    // 改进点:确保 TaskID 的正确性,假设 Manager 或 updatePlatform 有相关字段
    // 注意:这里需要根据实际业务逻辑确认 TaskID 的来源
    // 如果没有明确的 taskID,且必须传值,请确认 1 是否是约定的默认值
    taskID := int64(1) 
    // 尝试获取真实的 taskID (伪代码,需根据实际结构调整)
    // if m.taskID != 0 { taskID = m.taskID }
    // if m.updatePlatform.GetTaskID() != 0 { taskID = m.updatePlatform.GetTaskID() }

    m.updatePlatform.PostProcessEventMessage(updateplatform.ProcessEvent{
        TaskID:       taskID, // 替换硬编码的 1
        EventType:    updateplatform.GetUpdateEvent,
        EventStatus:  true,
        EventContent: msgContent,
    })
}()

总结

这段代码改动主要目的是在更新源成功后增加事件上报流程,并限制了该流程仅在特定版本(私有版)下生效。
最需要关注的问题是 TaskID 的硬编码,这可能会影响后续的数据追踪和调试。建议核实正确的 TaskID 来源并进行修改。其余部分逻辑清晰,性能和安全风险较低。

@qiuzhiqian qiuzhiqian merged commit 24364c3 into intranet_update Jan 23, 2026
23 of 28 checks passed
@qiuzhiqian qiuzhiqian deleted the fix_intranet branch January 23, 2026 03:35
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

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