Skip to content

fix: remove old cache on serial upgrade in repareCache - #151

Closed
deepin-wm wants to merge 1 commit into
linuxdeepin:masterfrom
deepin-wm:fix-dconfig-serial-upgrade-cache
Closed

fix: remove old cache on serial upgrade in repareCache#151
deepin-wm wants to merge 1 commit into
linuxdeepin:masterfrom
deepin-wm:fix-dconfig-serial-upgrade-cache

Conversation

@deepin-wm

Copy link
Copy Markdown

When the serial of a dconfig configuration is upgraded, the old cache values should be discarded. Currently repareCache() does not handle serial upgrades, causing the stale cache to persist and checkSerial() to fail.

Changes:

  1. repareCache(): Added serial upgrade handling — when newMeta->serial(key) > oldMeta->serial(key), use cache->remove(key) to remove the old cache value
  2. Added comment: // Serial升级时移除旧缓存值,serial升级意味着旧值必须废弃
  3. Added debug log for serial upgrade cache removal

1. Add serial upgrade handling in repareCache() to remove old
   cache values when newMeta serial is greater than oldMeta
   serial
2. Add debug log for serial upgrade cache removal

Log: Fixed dconfig write failure after serial upgrade

Influence:
1. Test that cache values are removed when serial is upgraded
2. Verify dconfig set succeeds after serial upgrade with same
   value
3. Test that repareCache handles serial downgrade gracefully

fix: repareCache添加serial升级时移除旧缓存处理

1. 在repareCache()中添加serial升级处理逻辑,当新meta的
   serial大于旧meta的serial时移除旧缓存值
2. 添加serial升级缓存移除的调试日志

Log: 修复dconfig serial升级后写入相同值失败的问题

Influence:
1. 测试serial升级时缓存值是否被正确移除
2. 验证serial升级后使用相同值设置dconfig是否成功
3. 测试repareCache对serial降级的处理
@deepin-ci-robot

Copy link
Copy Markdown

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-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: deepin-wm

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

@18202781743
18202781743 requested a review from mhduiy June 24, 2026 02:54
@18202781743
18202781743 marked this pull request as ready for review June 24, 2026 02:54
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:100分

■ 【总体评价】

代码精准修复了Serial升级时旧缓存未清除的缺陷,逻辑严密且无安全风险
语法逻辑完全正确,代码质量良好,性能无损耗,满足满分要求

■ 【详细分析】

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

新增代码在 dconfigresource.cppDSGConfigResource::repareCache 函数末尾,通过遍历 intersectKeys 并比较 newMeta->serial(key)oldMeta->serial(key) 的大小关系来决定是否调用 cache->remove(key),逻辑严密,符合C++标准语法及Qt编程规范。

  • 2.代码质量(良好)✓

新增代码包含清晰的注释说明修复意图,日志输出使用 qDebug 并携带了 resourceuidkey 等关键上下文信息,便于问题追踪与排查,且与原有代码风格保持高度一致。

  • 3.代码性能(无性能问题)✓

新增的 for 循环仅针对配置交集键进行遍历,在配置管理场景中交集键数量通常极少,serial() 比较与 remove() 操作的时间复杂度可视为常数级,不会引入性能瓶颈。

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

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
代码未引入任何新的安全风险,日志打印的 m_keykey 均为系统预定义的配置元数据键名,非外部不可信输入,不存在注入或信息泄露风险;指针使用均在安全上下文中。

■ 【改进建议代码示例】

// 当前代码已足够优秀,无需额外修改。以下为保留原始逻辑的完整上下文示意:
void DSGConfigResource::repareCache(DConfigCache *cache, DConfigMeta *oldMeta, DConfigMeta *newMeta)
{
    // ... (前置的 intersectKeys 处理逻辑) ...

    // Serial升级时移除旧缓存值,serial升级意味着旧值必须废弃
    for (const auto &key : intersectKeys) {
        if (newMeta->serial(key) > oldMeta->serial(key)) {
            cache->remove(key);
            qDebug(cfLog, "Cache removed because of serial upgraded, resource:%s, uid:%d, key:%s.",
                   qPrintable(m_key), cache->uid(), qPrintable(key));
        }
    }
}

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