Skip to content

fix(device): dispatch device load notifications on GUI thread#454

Merged
wyu71 merged 1 commit into
linuxdeepin:masterfrom
wyu71:master
Jul 10, 2026
Merged

fix(device): dispatch device load notifications on GUI thread#454
wyu71 merged 1 commit into
linuxdeepin:masterfrom
wyu71:master

Conversation

@wyu71

@wyu71 wyu71 commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Log: 修复设备相册加载期间的跨线程计时器告警
Influence: 设备相册加载提示与文件监控计时器

@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 @wyu71, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

Log: 修复设备相册加载期间的跨线程计时器告警
Influence: 设备相册加载提示与文件监控计时器
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:100分

■ 【总体评价】

代码修复了跨线程GUI更新引发的崩溃和QTimer内存泄漏问题,质量优秀
逻辑正确且修复了严重的线程安全和内存管理缺陷,无需扣分

■ 【详细分析】

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

AlbumControl::loadDeviceAlbumInfoAsync 中通过 QMetaObject::invokeMethod 配合 Qt::QueuedConnection 将信号发射安全地转发至主线程,避免了非主线程操作GUI的崩溃问题。FileInotify::FileInotify 中为 QTimer 指定父对象 this,正确建立了对象树关系,修复了内存泄漏。
潜在问题:无
建议:无

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

代码修改符合Qt对象模型和线程安全规范,注释更新准确描述了跨线程调用的意图,代码简洁明了。
潜在问题:无
建议:无

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

Qt::QueuedConnection 仅在事件循环中增加一个槽调用,开销极小。修复内存泄漏避免了长期运行的性能退化。
潜在问题:无
建议:无

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

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
本次代码修改修复了内存泄漏和线程安全问题,未引入任何新的安全风险。

  • 建议:无

■ 【改进建议代码示例】

// 当前代码已为最佳实践,无需进一步修改
void AlbumControl::loadDeviceAlbumInfoAsync(const QString &devicePath)
{
    // ...
    m_PhonePicFileMap.insert(devicePath, nullptr);
    QThreadPool::globalInstance()->start([=](){
        // Notify QML through the GUI thread before updating the loading dialog.
        QMetaObject::invokeMethod(qApp, [=](){
            Q_EMIT deviceAlbumInfoLoadStart(devicePath);
        }, Qt::QueuedConnection);
        // ...
    });
}

FileInotify::FileInotify(QObject *parent)
    : QObject(parent)
{
    // ...
    m_timer = new QTimer(this);
    connect(m_timer, &QTimer::timeout, this, &FileInotify::onNeedSendPictures);
    // ...
}

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: pengfeixx, wyu71

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

@wyu71
wyu71 merged commit baaaebd into linuxdeepin:master Jul 10, 2026
18 of 20 checks passed
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