Skip to content

fix: add serial comparison in DConfigCacheImpl::setValue#568

Open
deepin-wm wants to merge 1 commit into
linuxdeepin:masterfrom
deepin-wm:fix-dconfig-serial-compare
Open

fix: add serial comparison in DConfigCacheImpl::setValue#568
deepin-wm wants to merge 1 commit into
linuxdeepin:masterfrom
deepin-wm:fix-dconfig-serial-compare

Conversation

@deepin-wm

Copy link
Copy Markdown

When the serial of a dconfig configuration is upgraded, and the user sets the same value again, DConfigCacheImpl::setValue() only compares the value without comparing the serial. This causes the cache serial to not be updated, checkSerial() fails, and the value falls back to the default.

Changes:

  1. DConfigCacheImpl::setValue(): Added serial comparison condition — when value is the same but serial differs, the cache is forced to update
  2. Updated two setValue() doc comments to reflect new return value semantics: true if the cache was updated (value or serial changed), false if no update was needed

@deepin-ci-robot

Copy link
Copy Markdown
Contributor

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sorry @deepin-wm, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@deepin-wm deepin-wm force-pushed the fix-dconfig-serial-compare branch from 3ec1ea8 to d8ad8ce Compare June 23, 2026 10:12
@18202781743 18202781743 force-pushed the fix-dconfig-serial-compare branch from d8ad8ce to 23b7840 Compare June 24, 2026 02:23
@18202781743 18202781743 marked this pull request as ready for review June 24, 2026 02:24

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sorry @18202781743, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@18202781743 18202781743 requested review from BLumia and mhduiy June 24, 2026 02:24
1. Fix incorrect early return when checking value equality without
serial comparison
2. Add DConfigInfo::checkSerial to compare both value and serial before
returning false
3. Update setValue documentation to accurately describe return behavior
4. Add unit tests covering serial comparison scenarios:
   - Same value and same serial returns false
   - Same value but different serial returns true (bug fix)
   - Different value and same serial returns true
   - Different value and different serial returns true
5. Add test meta and override data files for serial testing
6. Update copyright year from 2023 to 2026

fix: 修复DConfigCache的setValue中序列号比较逻辑

1. 修正仅检查值相等就提前返回的错误逻辑
2. 增加DConfigInfo::checkSerial同时比较值和序列号
3. 更新setValue文档准确描述返回值行为
4. 添加涵盖序列号比较场景的单元测试:
   - 相同值和相同序列号返回false
   - 相同值但不同序列号返回true(bug修复)
   - 不同值相同序列号返回true
   - 不同值不同序列号返回true
5. 添加序列号测试所需的元数据和覆盖文件
6. 更新版权年份从2023到2026

Influence:
1. Test DConfig setValue when value is same but serial is updated via
override
2. Verify no regression when setting different values with same or
different serials
3. Validate cache update behavior matches documented return semantics
4. Ensure override layer serial changes properly trigger value updates

Influence:
1. 测试当值相同但通过覆盖文件更新序列号时setValue的行为
2. 验证设置不同值(相同或不同序列号)时无回归
3. 确认缓存更新行为符合文档中的返回语义
4. 确保覆盖层序列号变化能正确触发值更新
@18202781743 18202781743 force-pushed the fix-dconfig-serial-compare branch from 23b7840 to c2b27a0 Compare June 24, 2026 02:41
@deepin-ci-robot

Copy link
Copy Markdown
Contributor

deepin pr auto review

★ 总体评分:100分

■ 【总体评价】

代码完善了配置缓存更新时的序列号校验逻辑,质量优秀且无任何安全风险
逻辑完全正确,测试覆盖全面,符合满分标准

■ 【详细分析】

  • 1.语法逻辑(完全正确)✓

在 src/dconfigfile.cpp 的 DConfigCacheImpl::setValue 函数中,将原有的单值比对扩展为值与序列号的双重比对,修复了当值相同但序列号变更时缓存未更新的逻辑缺陷。测试用例 ut_dconfigfile.cpp 中的 setValueWithSerialComparison 覆盖了值与序列号的四种正交组合场景,断言严谨。
建议:无

  • 2.代码质量(优秀)✓

更新了原有含糊的注释为精确的英文描述,明确了返回值的真实语义。新增的测试数据文件命名清晰,测试代码利用 FileCopyGuard 进行资源管理,避免了测试用例间的文件污染,符合现代 C++ 测试规范。
建议:无

  • 3.代码性能(高效)✓

新增的 DConfigInfo::checkSerial 及 values.serial 调用仅涉及简单的整数比对操作,在配置更新的低频调用场景下对性能的影响完全可忽略。
建议:无

  • 4.代码安全(存在0个安全漏洞)✓

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
代码变更仅涉及内存内部的逻辑比对与静态测试资源的增加,不涉及任何外部输入解析、命令执行或越权访问,无攻击面。

  • 建议:保持现有的安全编码习惯

■ 【改进建议代码示例】

// 当前代码已足够优秀,无需额外修改,此处展示其核心逻辑以供参考
bool setValue(const QString &key, const QVariant &value, const int serial, const uint uid, const QString &appid) override
{
    // 双重校验:值相等且序列号未变更时,跳过无意义的更新操作
    if (values.value(key) == value && DConfigInfo::checkSerial(values.serial(key), serial)) {
        return false;
    }
    values.setValue(key, value);
    // ...后续逻辑
}

@deepin-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: deepin-wm, 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

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