Skip to content

fix(view): defer all-items grid initialization#465

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

fix(view): defer all-items grid initialization#465
wyu71 merged 1 commit into
linuxdeepin:masterfrom
wyu71:master

Conversation

@wyu71

@wyu71 wyu71 commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Reuse the all-items model for the title and defer grid initialization.
复用全部合集模型计算标题,并在首帧后创建缩略图网格。

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

Reuse the all-items model for the title and defer grid initialization.
复用全部合集模型计算标题,并在首帧后创建缩略图网格。

Log: 优化全部合集首屏标题与缩略图加载时序
Influence: 全部合集首屏日期、缩略图显示和启动阶段导入刷新
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:95分

■ 【总体评价】

代码通过延迟加载机制优化了相册视图的首帧渲染性能,并修复了ThumbnailModel中的空指针解引用崩溃问题
逻辑正确且性能提升明显,仅因QML中部分复杂状态管理逻辑扣减少量分数

■ 【详细分析】

  • 1.语法逻辑(基本正确)✓

thumbnailmodel.cpp 第112行修复了空指针解引用问题,增加了对 sourceModel() 返回值的校验。imagedatamodel.cpp 新增的 urlAt 方法进行了越界检查。QML中通过 Loader 延迟加载视图,并在各处对 theViewLoader.item 进行了非空判断。
潜在问题:QML中 initialContentActivationPendinginitialContentRefreshPending 等多个状态标志的交互逻辑较为复杂,在极端时序下可能存在状态不同步的风险
建议:考虑使用状态机(State Machine)或简化状态标志的依赖关系,确保生命周期管理的清晰度

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

代码中添加了详细的英文注释,解释了延迟加载和状态管理的目的。C++代码新增的接口符合Qt的命名规范,且使用了 Q_INVOKABLE 宏以便QML调用。
潜在问题:AllCollection.qml 中引入了较多分散的布尔属性来控制初始化流程,增加了维护成本
建议:将相关的初始化状态封装为一个单独的组件或自定义属性组,降低顶层组件的复杂度

  • 3.代码性能(良好)✓

ThumbnailListViewAlbum 放入 Loader 中并设置 active: false,实现了视图的按需加载,避免了首帧渲染时的沉重开销。updateTitle 函数在视图未加载时通过共享数据模型提前计算显示范围,减少了重复数据库查询。
潜在问题:onWidthChangedonHeightChanged 频繁触发 scheduleInitialTitle(),可能在高频窗口缩放时产生大量定时器重启
建议:可以引入防抖(debounce)机制,或者在窗口缩放结束时才触发重新计算

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

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
本次代码变更主要涉及界面逻辑优化和空指针修复,未引入外部输入处理或敏感操作,不存在安全风险。urlAt 方法的越界检查有效防止了潜在的越界读取。

  • 建议:继续保持对用户输入和模型边界的严格校验

■ 【改进建议代码示例】

// src/src/thumbnailview/thumbnailmodel.cpp
QHash<int, QByteArray> ThumbnailModel::roleNames() const
{
    qDebug() << "ThumbnailModel::roleNames - Entry";
    QHash<int, QByteArray> hash;
    if (auto *model = sourceModel()) {
        hash = model->roleNames();
    } else {
        qWarning() << "ThumbnailModel::roleNames - sourceModel() is null, returning base roles only.";
    }
    hash.insert(Roles::BlankRole, "blank");
    hash.insert(Roles::SelectedRole, "selected");
    hash.insert(Roles::Thumbnail, "thumbnail");
    return hash;
}

@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 06d917d into linuxdeepin:master Jul 23, 2026
17 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