Skip to content

fix(eventlogger): change event log enable condition from professional-only to non-community#192

Merged
Ivy233 merged 1 commit into
linuxdeepin:masterfrom
Ivy233:fix/eventlogger-enable-condition
May 20, 2026
Merged

fix(eventlogger): change event log enable condition from professional-only to non-community#192
Ivy233 merged 1 commit into
linuxdeepin:masterfrom
Ivy233:fix/eventlogger-enable-condition

Conversation

@Ivy233
Copy link
Copy Markdown
Contributor

@Ivy233 Ivy233 commented May 20, 2026

为 EventLogger 事件日志启用条件由仅专业版改为非社区版

PMS: BUG-362029

Summary by Sourcery

Bug Fixes:

  • Correct event logger enablement condition so it is active on all non-community editions instead of only the professional edition.

…-only to non-community 为 EventLogger 事件日志启用条件由仅专业版改为非社区版

PMS: BUG-362029
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented May 20, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR broadens the enablement condition for EventLogger so that event logging is active on all non-community UOS editions instead of only on the professional edition, by updating the logic in the central helper function and its documentation comments.

File-Level Changes

Change Details Files
Broaden EventLogger enablement from only professional edition to all non-community editions.
  • Updated shouldEnableEventLog() to return true when the system edition is anything other than UosCommunity instead of only when it equals UosProfessional.
  • Adjusted the accompanying comments to describe the new behavior of enabling event logs for all non-community editions.
cpp-include/eventlogger.hpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • Consider whether using a blacklist-style condition (!= UosCommunity) is future-proof enough; if additional editions are introduced later, you may want an explicit whitelist of enabled editions instead.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider whether using a blacklist-style condition (`!= UosCommunity`) is future-proof enough; if additional editions are introduced later, you may want an explicit whitelist of enabled editions instead.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@deepin-ci-robot
Copy link
Copy Markdown

deepin pr auto review

你好!我是CodeGeeX。我已仔细审查了你提供的 Git Diff。本次修改的核心逻辑是将事件日志的启用策略从“仅限专业版”变更为“除社区版外全部启用”。

以下是我对该代码修改在语法逻辑、代码质量、代码性能和代码安全方面的审查意见及改进建议:

1. 语法逻辑

  • 逻辑正确性:从逻辑上看,将 == UosProfessional 改为 != UosCommunity 实现了预期的需求。但是,这里存在一个潜在的逻辑边界风险:如果未来 Dtk 库新增了一个系统版本(例如 UosEducationUosCustom),新版本会自动被启用日志。你需要确认这是否符合预期?如果是“仅针对已知版本启用”,那么使用白名单(==)更安全;如果确实是“未知版本也默认启用”,则当前黑名单(!=)逻辑是正确的。
  • 枚举值未定义风险:如果 DSysInfo::uosEditionType() 在某些老旧的 Dtk 版本中不存在 UosCommunity 枚举值,或者返回了未预期的整型数值,当前的比较逻辑可能会导致非预期的行为。

2. 代码质量

  • 注释与代码同步:注释更新得很及时,与代码逻辑保持了一致,这很好。
  • C++现代特性:该函数没有接收任何参数,且内部只做逻辑判断,没有修改任何状态,建议使用 constexpr 修饰(前提是底层 DSysInfo::uosEditionType() 在编译期可求值,若不行则保持 inline)。同时,C++11 引入了类型别名,建议将底部的 typedef 替换为 using,以提升代码的现代感和可读性。

3. 代码性能

  • 函数调用开销inline 关键字已经向编译器建议内联,减少了函数调用开销,这很好。
  • 底层API性能DSysInfo::uosEditionType() 通常是通过读取系统文件(如 /etc/os-version)或读取环境变量来获取版本信息的。如果在高频调用的场景下(例如每次记录日志都调用一次 shouldEnableEventLog()),可能会产生不必要的 I/O 开销。
    • 改进建议:如果该函数会被频繁调用,建议在内部增加一个 static const bool 缓存,使得版本判断只进行一次。

4. 代码安全

  • 信息泄露风险:该函数本身只是返回一个布尔值,不涉及敏感数据输出。
  • 符号可见性:作为头文件中的函数,shouldEnableEventLog 默认具有外部链接属性,可能被其他动态库或程序意外拦截/覆盖。如果是库内部使用,建议增加命名空间限制或使用匿名命名空间(如果仅限当前编译单元使用,但这里是头文件,所以保持命名空间即可)。
  • 函数指针类型定义typedef bool (*Initialize)(const std::string &package_id, bool enable_sig); 暴露了内部实现细节,需确保此函数指针不被外部恶意替换。

综合改进后的代码建议

基于以上分析,如果你确认“除社区版外全部启用”的业务逻辑无误,我建议对代码进行如下优化(主要针对代码质量和潜在性能问题):

namespace DDE_EventLogger {
 
// Check if event logging should be enabled based on system edition
// Enable for all editions except UosCommunity
inline bool shouldEnableEventLog()
{
    // Performance optimization: cache the result to avoid repeated system info queries.
    // DSysInfo::uosEditionType() might involve file I/O, so we only evaluate it once.
    static const bool enabled = []() {
        // Note: DSysInfo is in Dtk::Core namespace
        return Dtk::Core::DSysInfo::uosEditionType() != Dtk::Core::DSysInfo::UosCommunity;
    }();
    return enabled;
}
 
// Modern C++ type alias instead of typedef
using Initialize = bool(*)(const std::string &package_id, bool enable_sig);

} // namespace DDE_EventLogger

改进点说明:

  1. 静态局部变量缓存:使用 static const bool enabled 配合 Lambda 表达式,确保 DSysInfo::uosEditionType() 仅在第一次调用时执行一次,后续调用直接返回缓存的结果,大幅提升高频调用场景下的性能。
  2. 现代类型别名:将 typedef 替换为 using,语法更清晰,尤其在函数指针类型定义时更符合现代 C++ 风格。

@Ivy233 Ivy233 requested review from 18202781743 and mhduiy May 20, 2026 05:19
@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Ivy233, mhduiy

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

@Ivy233 Ivy233 merged commit d9f5713 into linuxdeepin:master May 20, 2026
18 checks passed
@Ivy233 Ivy233 deleted the fix/eventlogger-enable-condition branch May 20, 2026 05:50
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